File tree Expand file tree Collapse file tree 1 file changed +55
-2
lines changed
Expand file tree Collapse file tree 1 file changed +55
-2
lines changed Original file line number Diff line number Diff line change @@ -63,9 +63,62 @@ static App()
6363
6464 protected override void OnStartup ( StartupEventArgs e )
6565 {
66- AppDomain . CurrentDomain . UnhandledException += ( sender , args ) =>
66+ // Exception handling events which are not caught in the Task thread
67+ TaskScheduler . UnobservedTaskException += ( _ , e ) =>
6768 {
68- ProcessHelper . WriteLog ( ( ( Exception ) args . ExceptionObject ) . ToString ( ) ) ;
69+ try
70+ {
71+ ProcessHelper . WriteLog ( e . Exception . ToString ( ) ) ;
72+ Wpf . Ui . Violeta . Controls . ExceptionReport . Show ( e . Exception ) ;
73+ }
74+ catch ( Exception ex )
75+ {
76+ ProcessHelper . WriteLog ( ex . ToString ( ) ) ;
77+ }
78+ finally
79+ {
80+ e . SetObserved ( ) ;
81+ }
82+ } ;
83+
84+ // Exception handling events which are not caught in UI thread
85+ DispatcherUnhandledException += ( _ , e ) =>
86+ {
87+ try
88+ {
89+ ProcessHelper . WriteLog ( e . Exception . ToString ( ) ) ;
90+ Wpf . Ui . Violeta . Controls . ExceptionReport . Show ( e . Exception ) ;
91+ }
92+ catch ( Exception ex )
93+ {
94+ ProcessHelper . WriteLog ( ex . ToString ( ) ) ;
95+ }
96+ finally
97+ {
98+ e . Handled = true ;
99+ }
100+ } ;
101+
102+ // Exception handling events which are not caught in Non-UI thread
103+ // Such as a child thread created by ourself
104+ AppDomain . CurrentDomain . UnhandledException += ( _ , e ) =>
105+ {
106+ try
107+ {
108+ if ( e . ExceptionObject is Exception ex )
109+ {
110+ ProcessHelper . WriteLog ( ex . ToString ( ) ) ;
111+ Wpf . Ui . Violeta . Controls . ExceptionReport . Show ( ex ) ;
112+ }
113+ }
114+ catch ( Exception ex )
115+ {
116+ ProcessHelper . WriteLog ( ex . ToString ( ) ) ;
117+ }
118+ finally
119+ {
120+ // Ignore
121+ }
69122 } ;
70123
71124 // Initialize MessageBox patching
You can’t perform that action at this time.
0 commit comments