WPF global exception handler [duplicate]
https://*.com/questions/1472498/wpf-global-exception-handler/1472562#1472562
You can trap unhandled exceptions at different levels:
-
AppDomain.CurrentDomain.UnhandledException
From all threads in the AppDomain. -
Dispatcher.UnhandledException
From a single specific UI dispatcher thread. -
Application.Current.DispatcherUnhandledException
From the main UI dispatcher thread in your WPF application. -
TaskScheduler.UnobservedTaskException
from within each AppDomain that uses a task scheduler for asynchronous operations.
You should consider what level you need to trap unhandled exceptions at.
Deciding between #2 and #3 depends upon whether you‘re using more than one WPF thread. This is quite an exotic situation and if you‘re unsure whether you are or not, then it‘s most likely that you‘re not.
Globally catch exceptions in a WPF application?
Use the Application.DispatcherUnhandledException Event
. See this question for a summary (see Drew Noakes‘ answer).
Be aware that there‘ll be still exceptions which preclude a successful resuming of your application, like after a stack overflow, exhausted memory, or lost network connectivity while you‘re trying to save to the database.