- A+
public App()
{
//UI线程异常
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
//非UI线程异常
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
//可以记录日志并转向错误bug窗口友好提示用户
e.Handled = true;
Notice.Show("抱歉给您带来不便!消息:" + e.Exception.Message, "系统错误", MessageBoxIcon.Error);
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
//可以记录日志并转向错误bug窗口友好提示用户
if (e.ExceptionObject is System.Exception)
{
Exception ex = (System.Exception)e.ExceptionObject;
Notice.Show("抱歉给您带来不便!消息:" + ex.Message,"系统错误",MessageBoxIcon.Error);
}
}