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
Pingback: UnhandledExceptionDispatcher for WPF app « maonet technotes