Wpf 全局異常捕獲處理

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;this

Notice.Show("抱歉給您帶來不便!消息:" + e.Exception.Message, "系統錯誤", MessageBoxIcon.Error);spa

}
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);
}
}io

相關文章
相關標籤/搜索