View Single Post
Old October 17, 2017, 23:00   #26
Dean Anderson
Adept
 
Join Date: Nov 2009
Posts: 124
Dean Anderson is on a distinguished road
Of course, C# has the classic:

Code:
try
{
    code here
}
catch (Exception e)
{
    exception code for handling exceptions here
}
finally
{
    clean-up code here
}
In the above, the catch can handle some types of exception or all exceptions (and you can have more than one catch block for different types of exception), and any that are not caught will be propagated back to the code that called the function - which is what will also happen if you don't put a try/catch block in at all and an exception happens.

The code in the finally block is guaranteed to execute before the function returns regardless of whether or not there is an exception and regardless of whether or not it is handled.

Having said that, I've not got any exception handling code in there yet. At the moment, I want exceptions to be unhandled and to be caught by the debugger so that I can see what's going wrong.
Dean Anderson is offline   Reply With Quote