Unhandled exceptions in children threads

When an exception is thrown in a thread that is not the main thread, it can be catch with the event UnhandledException of the AppDomain class. However attaching this event can not avoid the application to crash.

There are two ways to workaround this issue:

  1. One of this is managed the exceptions explicitly with try ... catch in each thread, the catch statement would have to handle the exception and not rethrown it.
  2. The second solution is set the CLR work as in the previous versions (1.0 and 1.1). It is not a recommended approach. In order to do that you need add the following configuration setting in your application configuration file:

<runtime>

    <legacyUnhandledExceptionPolicy enabled="1"/>

</runtime>

Published Saturday, October 13, 2007 8:32 PM by marianor
Filed under:

Comments

# re: Unhandled exceptions in children threads

Saturday, October 13, 2007 9:37 PM by jayson knight

For WinForms, a good alternative is Application.ThreadException.

# re: Unhandled exceptions in children threads

Thursday, November 22, 2007 7:04 PM by marianor

The Application.ThreadException only get exceptions from the dispatcher (UI thread) and not other background threads.

Leave a Comment

(required) 
(required) 
(optional)
(required)