This is a mirror of official site: http://jasper-net.blogspot.com/

Order in Chaos: Handling unhandled exceptions in a WPF application

| Monday, August 29, 2011
Introduction

So you want to handle somehow all the unhandled exceptions in your application.
Usually you want to accomplish one of the following:

    Log the exception for later diagnostics
    Present the user an unhandled exception UI, nicer than the default

You heard there’s an event you should register, or maybe you find one by mistake, but is it the correct one?

Did you know there are four (!) different events for handling unhandled exceptions in the .NET framework?

So what is the difference between them and when should we use each one?
This post will hopefully answer these questions.

Note: this is NOT a replacement for try-catch blocks!

 
Summary

I’ll begin with the summary to avoid boring busy developers.

In a typical WPF application you should use Application.Current.DispatcherUnhandledException for exceptions generated on the UI thread and AppDomain.CurrentDomain.UnhandledException for all the other exceptions.

Now, for the details..

 
System.Windows.Forms.Application.ThreadException

This event is used for catching unhandled exceptions only on UI threads created by WinForms. Other exceptions, generated on non-UI threads won’t arrive to this event. Use AppDomain.Current.UnhandledException to catch them.


Read more: Arik Poznanski's Blog
QR: order-in-chaos-handling-unhandled-exceptions-in-a-wpf-application.aspx

Posted via email from Jasper-net

0 comments: