Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between UnhandledException and DispatcherUnhandledException in .NET

What is the difference between AppDomain.UnhandledException and Application.DispatcherUnhandledException in .NET?

I need an event that is fired when any unhandled exception occurs. I have come across these two, but I dont know in what ways they differ from each other. Also, are there cases when they are not fired?

like image 940
user246392 Avatar asked Jul 09 '10 11:07

user246392


1 Answers

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.

like image 159
Quartermeister Avatar answered Sep 19 '22 21:09

Quartermeister