Application.DispatcherUnhandledException Event

Occurs when an exception is raised by the application but not handled.

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public event DispatcherUnhandledExceptionEventHandler DispatcherUnhandledException
/** @event */
public void add_DispatcherUnhandledException (DispatcherUnhandledExceptionEventHandler value)

/** @event */
public void remove_DispatcherUnhandledException (DispatcherUnhandledExceptionEventHandler value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
<object DispatcherUnhandledException="DispatcherUnhandledExceptionEventHandler" .../>

By default, Windows Presentation Foundation (WPF) catches unhandled exceptions, notifies users of the exception from a dialog box (from which they can report the exception), and automatically shuts down an application. However, if an application needs to perform custom unhandled exception processing from a centralized location, you should handle DispatcherUnhandledException.

DispatcherUnhandledException is raised by an Application for each exception that is not handled within the AppDomain that the Application object was created in.

The DispatcherUnhandledException event handler is passed a DispatcherUnhandledExceptionEventArgs argument that contains contextual information regarding the exception, including:

You can use this information to determine whether an exception is recoverable or not. A recoverable exception might be a FileNotFoundException, for example, while an unrecoverable exception might be a StackOverflowException, for example.

When you process an unhandled exception from DispatcherUnhandledException, and you don't want WPF to continue processing it, you need to set the Handled property to true.

Unlike the other events that Application raises, DispatcherUnhandledException does not have a matching protected virtual implementation (eg OnDispatcherUnhandledException). Consequently, classes that derive from Application must always register an event handler with DispatcherUnhandledException to process unhandled exceptions.

The following example shows how to process unhandled exceptions by handling the DispatcherUnhandledException event.

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;

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0