Note: This post was written a while back but sat in draft. I’ve published this now, but I’m not sure it’s relevant to the latest versions etc. so please bear this in mind.
None of us want our applications to just crash when an exception occurs so we often ensure we’ve got catch blocks around possible exceptions, but ofcourse, sometimes we either don’t care to handle an exception explicitly or we forget to code the catch block or the place the exception occurs such that it’s not possible to handle in such a structured way. In such scenarios we want to handle all “unhandled” exceptions at the application level.
Let’s take a look at some of the ways to handle exceptions in a WPF application. Here’s a list some of those ways to handle “unhandled” exceptions.
AppDomain.UnhandledException
The AppDomain.UnhandledException or more specifically AppDomain.CurrentDomain.UnhandledException.
Application.DispatcherUnhandledException
The Application.DispatcherUnhandledException or more specifically the Application.Current.DispatcherUnhandledException
Dispatcher.UnhandledException
The Dispatcher.UnhandledException or more specifically Dispatcher.CurrentDispatcher.UnhandledException
AppDomain.FirstChanceException
The AppDomain.FirstChanceException or more specifically AppDomain.CurrentDomain.FirstChanceException.
TaskScheduler.UnobservedTaskException