I started a new WPF project in VS2008 and then added some code to trap DispatcherUnhandledException. Then I added a throw exception to Window1 but the error is not trapped by the handler. Why?
public App() { this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException); } void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { System.Windows.MessageBox.Show(string.Format('An error occured: {0}', e.Exception.Message), 'Error'); e.Handled = true; } void Window1_MouseDown(object sender, MouseButtonEventArgs e) { throw new NotImplementedException(); }
This can happen because of the way you have the debugger handling exceptions — Debug/Exceptions… should allow you to configure exactly how you want it handled.