Alex Rivera | Logout

What's the difference between Application.ThreadException and AppDomain.CurrentDomain.UnhandledException?

Asked 2010-01-06T16:48:05.483
116

Alright, this is an easy one:

  • What's the difference between Application.ThreadException and
    AppDomain.CurrentDomain.UnhandledException?

  • Do I need to handle both?

Thanks!

Edit
Report

1 Answer

38

From source:

In applications that use Windows Forms, unhandled exceptions in the main application thread cause the Application.ThreadException event to be raised. If this event is handled, the default behavior is that the unhandled exception does not terminate the application, although the application is left in an unknown state. In that case, the UnhandledException event is not raised. This behavior can be changed by using the application configuration file, or by using the Application.SetUnhandledExceptionMode method to change the mode to UnhandledExceptionMode.ThrowException before the ThreadException event handler is hooked up. This applies only to the main application thread. The UnhandledException event is raised for unhandled exceptions thrown in other threads.

Starting with Visual Studio 2005, the Visual Basic application framework provides another event for unhandled exceptions in the main application thread - WindowsFormsApplicationBase.UnhandledException. This event has an event arguments object with the same name as the event arguments object used by AppDomain.UnhandledException, but with different properties. In particular, this event arguments object has an ExitApplication property that allows the application to continue running, ignoring the unhandled exception (and leaving the application in an unknown state). In that case, the AppDomain.UnhandledException event is not raised.

Application.ThreadException can be caught and the application could continue (in general is not a great idea, but for the application like running periodically some acti

answered 2010-05-18T21:17:38.447

Your Answer