mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 19:49:15 +08:00
36 lines
1020 B
C#
36 lines
1020 B
C#
using System;
|
|
using System.Windows;
|
|
using System.Windows.Threading;
|
|
using NLog;
|
|
using Wox.Infrastructure.Exception;
|
|
|
|
namespace Wox.Helper
|
|
{
|
|
public static class ErrorReporting
|
|
{
|
|
public static void Report(Exception e)
|
|
{
|
|
var logger = LogManager.GetLogger("UnHandledException");
|
|
logger.Fatal(ExceptionFormatter.FormatExcpetion(e));
|
|
new CrashReporter(e).Show();
|
|
}
|
|
|
|
public static void UnhandledExceptionHandle(object sender, UnhandledExceptionEventArgs e)
|
|
{
|
|
//handle non-ui thread exceptions
|
|
Application.Current.MainWindow.Dispatcher.Invoke(() =>
|
|
{
|
|
Report((Exception)e.ExceptionObject);
|
|
});
|
|
}
|
|
|
|
public static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
|
{
|
|
//handle ui thread exceptions
|
|
Report(e.Exception);
|
|
//prevent crash
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|