Handle/Display UnhandleException in WPF

From MSDN, unhandledExcpetion can be handled genereally in application.xaml,

<Application
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="SDKSample.App"
  StartupUri="MainWindow.xaml"
  DispatcherUnhandledException="App_DispatcherUnhandledException" />

using System.Windows; // Application
using System.Windows.Threading; // DispatcherUnhandledExceptionEventArgs

namespace SDKSample
{
    public partial class App : Application
    {
        void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            // Process unhandled exception

...

            // Prevent default unhandled exception processing
            e.Handled = true;
        }
    }
}

I like this very much, but suggestion from IglooCoder is, you don’t want set Handled=true, the UnHandleException should keep unhanded in this UnhandledException event, for specific exception you want to handle, do it on screen or somewhere else, like local WcfProxy. This event should be the place you want to display error or log or send screen shot to admin. Anyway, exceptions shouldn’t be handled here.

Advertisements

One thought on “Handle/Display UnhandleException in WPF

  1. Pingback: UnhandledExceptionDispatcher for WPF app « maonet technotes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s