@@ -200,83 +200,57 @@ public static void SaveSessionTabs()
200
200
. ToList ( ) ;
201
201
}
202
202
203
- /// <summary>
204
- /// Invoked when an exception is not handled on the UI thread.
205
- /// </summary>
206
- public static void App_UnhandledException ( object sender , Microsoft . UI . Xaml . UnhandledExceptionEventArgs e )
207
- {
208
- AppUnhandledException ( e . Exception , true ) ;
209
- }
210
-
211
- /// <summary>
212
- /// Invoked when an exception is not handled on the current thread.
213
- /// </summary>
214
- public static void CurrentDomain_UnhandledException ( object sender , System . UnhandledExceptionEventArgs e )
215
- {
216
- AppUnhandledException ( e . ExceptionObject as Exception , false ) ;
217
- }
218
-
219
- /// <summary>
220
- /// Invoked when an exception is not handled on a background thread.
221
- /// </summary>
222
- /// <remarks>
223
- /// This exception is sometimes occurred by forgotten <c>Task.Run(() => {...})</c>.
224
- /// </remarks>
225
- public static void TaskScheduler_UnobservedTaskException ( object ? sender , UnobservedTaskExceptionEventArgs e )
226
- {
227
- AppUnhandledException ( e . Exception , false ) ;
228
- }
229
-
230
203
/// <summary>
231
204
/// Shows exception on the Debug Output and sends Toast Notification to the Windows Notification Center.
232
205
/// </summary>
233
- private static void AppUnhandledException ( Exception ? ex , bool showToastNotification )
206
+ public static void HandleAppUnhandledException ( Exception ? ex , bool showToastNotification )
234
207
{
235
208
StringBuilder formattedException = new ( )
236
209
{
237
210
Capacity = 200
238
211
} ;
239
212
240
- formattedException . Append ( "--------- UNHANDLED EXCEPTION ---------" ) ;
213
+ formattedException . AppendLine ( "--------- UNHANDLED EXCEPTION ---------" ) ;
241
214
242
215
if ( ex is not null )
243
216
{
244
- formattedException . Append ( $ "\n >>>> HRESULT: { ex . HResult } \n ") ;
217
+ formattedException . AppendLine ( $ ">>>> HRESULT: { ex . HResult } ") ;
218
+
245
219
if ( ex . Message is not null )
246
220
{
247
- formattedException . Append ( " \n --- MESSAGE ---") ;
248
- formattedException . Append ( ex . Message ) ;
221
+ formattedException . AppendLine ( " --- MESSAGE ---") ;
222
+ formattedException . AppendLine ( ex . Message ) ;
249
223
}
250
224
if ( ex . StackTrace is not null )
251
225
{
252
- formattedException . Append ( " \n --- STACKTRACE ---") ;
253
- formattedException . Append ( ex . StackTrace ) ;
226
+ formattedException . AppendLine ( " --- STACKTRACE ---") ;
227
+ formattedException . AppendLine ( ex . StackTrace ) ;
254
228
}
255
229
if ( ex . Source is not null )
256
230
{
257
- formattedException . Append ( " \n --- SOURCE ---") ;
258
- formattedException . Append ( ex . Source ) ;
231
+ formattedException . AppendLine ( " --- SOURCE ---") ;
232
+ formattedException . AppendLine ( ex . Source ) ;
259
233
}
260
234
if ( ex . InnerException is not null )
261
235
{
262
- formattedException . Append ( " \n --- INNER ---") ;
263
- formattedException . Append ( ex . InnerException ) ;
236
+ formattedException . AppendLine ( " --- INNER ---") ;
237
+ formattedException . AppendLine ( ex . InnerException . ToString ( ) ) ;
264
238
}
265
239
}
266
240
else
267
241
{
268
- formattedException . Append ( " \n Exception is not available.\n ") ;
242
+ formattedException . AppendLine ( "Exception data is not available.") ;
269
243
}
270
244
271
- formattedException . Append ( "---------------------------------------" ) ;
245
+ formattedException . AppendLine ( "---------------------------------------" ) ;
272
246
273
247
Debug . WriteLine ( formattedException . ToString ( ) ) ;
274
248
275
249
// Please check "Output Window" for exception details (View -> Output Window) (CTRL + ALT + O)
276
250
Debugger . Break ( ) ;
277
251
278
252
SaveSessionTabs ( ) ;
279
- App . Logger . LogError ( ex , ex ? . Message ?? "An error occurred" ) ;
253
+ App . Logger . LogError ( ex , ex ? . Message ?? "An unhandled error occurred. " ) ;
280
254
281
255
if ( ! showToastNotification )
282
256
return ;
0 commit comments