Add global exception catching

This commit is contained in:
2dust
2024-08-30 13:47:53 +08:00
parent 9fdf6c6c32
commit b6c09470fc
5 changed files with 43 additions and 1 deletions

View File

@@ -15,6 +15,9 @@ public partial class App : Application
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
}
public override void OnFrameworkInitializationCompleted()
@@ -71,6 +74,19 @@ public partial class App : Application
}
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject != null)
{
Logging.SaveLog("CurrentDomain_UnhandledException", (Exception)e.ExceptionObject!);
}
}
private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
{
Logging.SaveLog("TaskScheduler_UnobservedTaskException", e.Exception);
}
private void OnExit(object? sender, ControlledApplicationLifetimeExitEventArgs e)
{
}