Catching Exceptions at Top Level in WPF


Add a handler for the DispatcherUnhandledException to the App.xaml file:

<Application x:Class="Main.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             DispatcherUnhandledException="Application_DispatcherUnhandledException"
             StartupUri="MainApplicationWindow.xaml">
    <Application.Resources>
       
    </Application.Resources>
</Application>

Add the handler for it to the App.xaml.cs file:


private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            // Do what you want here. The exception can be accessed via the event args e.
        }

Comments

Popular posts from this blog

Path environmental variable on mac

Setting up node-sass on a mac