Silent handle TaskSchedulerUnobservedTaskException

This commit is contained in:
Jack251970 2025-06-04 12:32:57 +08:00
parent 367bf2c3e7
commit 6b54ca28b0

View file

@ -11,10 +11,11 @@ namespace Flow.Launcher.Helper;
public static class ErrorReporting
{
private static void Report(Exception e, [CallerMemberName] string methodName = "UnHandledException")
private static void Report(Exception e, bool silent = false, [CallerMemberName] string methodName = "UnHandledException")
{
var logger = LogManager.GetLogger(methodName);
logger.Fatal(ExceptionFormatter.FormatExcpetion(e));
if (silent) return;
var reportWindow = new ReportWindow(e);
reportWindow.Show();
}
@ -36,7 +37,7 @@ public static class ErrorReporting
public static void TaskSchedulerUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
// handle unobserved task exceptions on UI thread
Application.Current.Dispatcher.Invoke(() => Report(e.Exception));
Application.Current.Dispatcher.Invoke(() => Report(e.Exception, true));
// prevent application exit, so the user can copy the prompted error info
e.SetObserved();
}