What is best practice to handle all Exceptions in WPF application?

Here a nice solution logging with NLog :

Logging in .NET with NLog (default config file, catch all exceptions and route to logger, ...)


AppDomain.CurrentDomain.UnhandledException

Will catch any unhandled exceptions for the current thread. This is how we handle it in our application.

BindingErrors are always handled and logged to the output window. Before a release we check the output window for binding errors and fix as many as we can.

However it is my opinion that you would not want to treat binding errors as unhandled as they mostly recoverable and should be fixed as best you can before each release. You can change Debug > Exeptions in Visual Studio to make it throw BindingFailure to get more specific information.


Keep in mind, that Microsoft does not recommend catching all exceptions, instead they recommend to catch only exceptions you know (or expect to happen in some place). Even more if you want to get "Certified for Microsoft [Windows|Vista]" logo, you must not catch unknown exceptions, and such exceptions must go to Wer.


Yes, there are 3 places:

  1. place Application.Run() into try ... catch
  2. DispatcherUnhandledException
  3. AppDomain.CurrentDomain.UnhandledException

In either case you should display a please-forgive-me message and suggest to send an error report.

The service on your server should answer either 'thank you for submitting error report' or 'the problem is already fixed in the next version. please update'