-
Notifications
You must be signed in to change notification settings - Fork 27
/
App.xaml.cs
66 lines (61 loc) · 1.96 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using Utility;
namespace PurchasePlatform
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
protected override void OnLoadCompleted(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnLoadCompleted(e);
Current.DispatcherUnhandledException += App_OnDispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
/// <summary>
/// UI线程抛出全局异常事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void App_OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
try
{
OliveLogger.Error("UI线程全局异常", e.Exception);
e.Handled = true;
}
catch (Exception ex)
{
OliveLogger.Error("不可恢复的UI线程全局异常", ex);
}
}
/// <summary>
/// 非UI线程抛出全局异常事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
var exception = e.ExceptionObject as Exception;
if (exception != null)
{
OliveLogger.Error("非UI线程全局异常", exception);
}
}
catch (Exception ex)
{
OliveLogger.Error("不可恢复的非UI线程全局异常", ex);
}
}
}
}