When you get the "ConsoleApplication1" has stopped responding, you have two choices.
If you press cancel, the unhandled exception is allowed to continue until eventually the application is terminated. This allows the finally
block to execute. If you do not press cancel then Windows Error Reporting halts the process, collects a minidump and then terminates the application. This means the finally
block is not executed.
Alternatively, if you handle the exception in a higher method you will definitely see the finally
block. For example:
static void unhandled()
{
try
{
throw new Exception();
}
finally
{
Console.WriteLine("finally");
}
}
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;
try
{
unhandled();
}
catch ( Exception )
{
// squash it
}
}
Always gives the output "finally"