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?
Application.DispatcherUnhandledExceptionwill handle exceptions thrown on the main UI thread in a WPF application.AppDomain.UnhandledExceptionwill 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 inAppDomain.UnhandledException.Also note that unhandled exceptions typically terminate the runtime, so after
AppDomain.UnhandledExceptionis raised your program will immediately exit. In contrast,Application.DispatcherUnhandledExceptionis catching exceptions and will let your program continue.