PowerToys/Wox/Helper/ErrorReporting.cs

42 lines
1.2 KiB
C#
Raw Normal View History

2015-01-11 21:52:30 +08:00
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Threading;
using Wox.Core.Exception;
using Wox.Infrastructure.Logger;
2015-01-16 23:42:12 +08:00
using MessageBox = System.Windows.MessageBox;
2015-01-11 21:52:30 +08:00
namespace Wox.Helper
{
public static class ErrorReporting
{
2015-01-16 23:42:12 +08:00
public static void Report(Exception e)
2015-01-11 21:52:30 +08:00
{
Log.Error(ExceptionFormatter.FormatExcpetion(e));
new CrashReporter.CrashReporter(e).Show();
}
public static void UnhandledExceptionHandle(object sender, UnhandledExceptionEventArgs e)
{
2015-01-16 23:42:12 +08:00
//handle non-ui thread exceptions
App.Window.Dispatcher.Invoke(new Action(() =>
{
Report((Exception)e.ExceptionObject);
if (!(e.ExceptionObject is WoxException))
{
Environment.Exit(0);
}
}));
2015-01-11 21:52:30 +08:00
}
public static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
2015-01-16 23:42:12 +08:00
//handle ui thread exceptions
2015-01-11 21:52:30 +08:00
Report(e.Exception);
2015-01-16 23:42:12 +08:00
//prevent crash
e.Handled = true;
2015-01-11 21:52:30 +08:00
}
}
}