我在 VS2008 中开始了一个新的 WPF 项目,然后在 trap 中添加了一些代码DispatcherUnhandledException
。然后我添加了一个抛出异常,Window1
但错误没有被处理程序捕获。为什么?
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();
}