public App()
{
Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show("UI系统出现异常,请联系管理员.", "UI意外的操作", MessageBoxButton.OK, MessageBoxImage.Information);
}
void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message);
MessageBox.Show("Code系统出现异常,请联系管理员.", "Code意外的操作", MessageBoxButton.OK, MessageBoxImage.Information);
e.Handled = true;//使用这一行代码告诉运行时,该异常被处理了,不再作为UnhandledException抛出了。
}