Difference between UnhandledException and DispatcherUnhandledException in .NET

DispatcherUnhandledException is raised only by the UI thread and only if an exception was raised while running an event. There's a bit of a tradition to handle these kind of exceptions specially, Windows Forms has it too with Application.ThreadException (poorly named, nothing to do with threads).

The reason is that there is a minor chance to handle the exception and keep the program alive since UI event handlers don't always mutate the state of program too dramatically. This takes large helpings of wishful thinking. Windows Forms takes this to an extreme, it displays a ThreadExceptionDialog that has a Continue button, allowing the user to ignore the exception. WPF does not do that, you'd have to write a dialog like that yourself. Which is why the event is there.

The default action of DispatcherUnhandledException is to not catch the exception. So you're okay to ignore it, AppDomain.UnhandledException will fire next.


Application.DispatcherUnhandledException will handle exceptions thrown on the main UI thread in a WPF application. AppDomain.UnhandledException will handle exceptions thrown on any thread and never caught. This includes threads you create manually or the main thread in a Console application. WPF is catching the exceptions on the UI thread, so you will not see those in AppDomain.UnhandledException.

Also note that unhandled exceptions typically terminate the runtime, so after AppDomain.UnhandledException is raised your program will immediately exit. In contrast, Application.DispatcherUnhandledException is catching exceptions and will let your program continue.