
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Polling an Asynchronous Delegate
|
1023
If the exception is rethrown from the catch block, the finally block of this struc-
tured exception handler will still execute. However, after the
finally block is fin-
ished, the rethrown exception is, at that point, rethrown. The rethrown exception
cannot be handled and the thread terminates. If there is any code after the
finally
block, it will not be executed, since an unhandled exception occurred.
Never rethrow an exception at the highest point in the exception-han-
dling hierarchy within a thread. Since no exception handlers can catch
this rethrown exception, it will be considered unhandled and the
thread will terminate after all
finally blocks have been executed.
What if you use the ThreadPool and QueueUserWorkItem? This method will still help
you because you added the handling code that will execute inside the thread. Just
make sure you have the
finally block set up so that you can notify yourself of excep-
tions in other threads as shown earlier.
In order to provide a last-chance exception handler for your WinForms application,
you need to hook up to two separate events. The first event is the
System.AppDomain.
CurrentDomain.UnhandledException
event, which will catch all unhandled exceptions
in the current AppDomain on worker threads; it will