Tag Archives: error handling

Understand when a finally block is executed in C#

Many programmers don’t understand (and many have forgotten) how the try catch finally block works. The basic syntax is: try { // Statements that could cause an error… } catch (Exception ex) { // Statements to execute if there is … Continue reading

Posted in syntax | Tagged , , , , , , , , , , , , | Leave a comment

Handle DataGridView errors in C#

This example shows how you can handle DataGridView errors when you modify the data in the DataGridView control. The example Build a DataTable and bind it to a DataGridView in C# shows how to use a DataGridView control to display … Continue reading

Posted in controls, database | Tagged , , , , , , , , , , , , , , | 1 Comment

Use try catch blocks to protect against unexpected errors in C#

Most programs cannot anticipate every possible error. You can watch for things like missing files, but it’s hard to stop a determined user from entering “ten” in a TextBox that should contain a number. (Actually you can prevent that by … Continue reading

Posted in debugging, syntax | Tagged , , , , , , , , , , , , , , | 1 Comment