Tôi đã bắt đầu một dự án WPF mới trong VS2008 và sau đó thêm một số mã vào bẫy DispatcherUnhandledException
. Sau đó, tôi thêm một ngoại lệ ném vào Window1
nhưng lỗi không bị xử lý bởi bẫy. Tại sao?WPF - DispatcherUnhandledException dường như không hoạt động
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();
}
Ngoại trừ mã trong danh sách sẽ ném ngoại lệ lên chuỗi giao diện người dùng chính. – svick
bị hạ cấp ... vì trong ví dụ ngoại lệ được ném vào chuỗi chính –