捕获未处理异常

This commit is contained in:
liufei
2022-01-05 17:11:24 +08:00
parent 19c8ff9d8d
commit 6038eee680

View File

@@ -21,6 +21,8 @@ namespace GeekDesk
public App()
{
this.Startup += new StartupEventHandler(App_Startup);
Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
private void App_Startup(object sender, StartupEventArgs e)
@@ -42,6 +44,7 @@ namespace GeekDesk
{
e.Handled = true;//使用这一行代码告诉运行时该异常被处理了不再作为UnhandledException抛出了。
LogUtil.WriteErrorLog(e, "未捕获异常!");
MessageBox.Show("GeekDesk遇到一个问题, 不用担心, 这不影响其它操作!");
}
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)