@@ -252,99 +252,94 @@ public static void SaveSessionTabs()
252
252
/// </summary>
253
253
public static void HandleAppUnhandledException ( Exception ? ex , bool showToastNotification )
254
254
{
255
- SafetyExtensions . IgnoreExceptions ( ( ) =>
255
+ var generalSettingsService = Ioc . Default . GetRequiredService < IGeneralSettingsService > ( ) ;
256
+
257
+ StringBuilder formattedException = new ( )
258
+ {
259
+ Capacity = 200
260
+ } ;
261
+
262
+ formattedException . AppendLine ( "--------- UNHANDLED EXCEPTION ---------" ) ;
263
+
264
+ if ( ex is not null )
256
265
{
257
- var generalSettingsService = Ioc . Default . GetRequiredService < IGeneralSettingsService > ( ) ;
266
+ ex . Data [ Mechanism . HandledKey ] = false ;
267
+ ex . Data [ Mechanism . MechanismKey ] = "Application.UnhandledException" ;
258
268
259
- StringBuilder formattedException = new ( )
269
+ SentrySdk . CaptureException ( ex , scope =>
260
270
{
261
- Capacity = 200
262
- } ;
271
+ scope . User . Id = generalSettingsService ? . UserId ;
272
+ scope . Level = SentryLevel . Fatal ;
273
+ } ) ;
263
274
264
- formattedException . AppendLine ( "--------- UNHANDLED EXCEPTION --------- ") ;
275
+ formattedException . AppendLine ( $ ">>>> HRESULT: { ex . HResult } ") ;
265
276
266
- if ( ex is not null )
277
+ if ( ex . Message is not null )
267
278
{
268
- ex . Data [ Mechanism . HandledKey ] = false ;
269
- ex . Data [ Mechanism . MechanismKey ] = "Application.UnhandledException" ;
270
-
271
- SentrySdk . CaptureException ( ex , scope =>
272
- {
273
- scope . User . Id = generalSettingsService ? . UserId ;
274
- scope . Level = SentryLevel . Fatal ;
275
- } ) ;
276
-
277
- formattedException . AppendLine ( $ ">>>> HRESULT: { ex . HResult } ") ;
278
-
279
- if ( ex . Message is not null )
280
- {
281
- formattedException . AppendLine ( "--- MESSAGE ---" ) ;
282
- formattedException . AppendLine ( ex . Message ) ;
283
- }
284
- if ( ex . StackTrace is not null )
285
- {
286
- formattedException . AppendLine ( "--- STACKTRACE ---" ) ;
287
- formattedException . AppendLine ( ex . StackTrace ) ;
288
- }
289
- if ( ex . Source is not null )
290
- {
291
- formattedException . AppendLine ( "--- SOURCE ---" ) ;
292
- formattedException . AppendLine ( ex . Source ) ;
293
- }
294
- if ( ex . InnerException is not null )
295
- {
296
- formattedException . AppendLine ( "--- INNER ---" ) ;
297
- formattedException . AppendLine ( ex . InnerException . ToString ( ) ) ;
298
- }
279
+ formattedException . AppendLine ( "--- MESSAGE ---" ) ;
280
+ formattedException . AppendLine ( ex . Message ) ;
299
281
}
300
- else
282
+ if ( ex . StackTrace is not null )
301
283
{
302
- formattedException . AppendLine ( "Exception data is not available." ) ;
284
+ formattedException . AppendLine ( "--- STACKTRACE ---" ) ;
285
+ formattedException . AppendLine ( ex . StackTrace ) ;
303
286
}
287
+ if ( ex . Source is not null )
288
+ {
289
+ formattedException . AppendLine ( "--- SOURCE ---" ) ;
290
+ formattedException . AppendLine ( ex . Source ) ;
291
+ }
292
+ if ( ex . InnerException is not null )
293
+ {
294
+ formattedException . AppendLine ( "--- INNER ---" ) ;
295
+ formattedException . AppendLine ( ex . InnerException . ToString ( ) ) ;
296
+ }
297
+ }
298
+ else
299
+ {
300
+ formattedException . AppendLine ( "Exception data is not available." ) ;
301
+ }
304
302
305
- formattedException . AppendLine ( "---------------------------------------" ) ;
306
-
307
- Debug . WriteLine ( formattedException . ToString ( ) ) ;
303
+ formattedException . AppendLine ( "---------------------------------------" ) ;
308
304
309
- // Please check "Output Window" for exception details (View -> Output Window) (CTRL + ALT + O)
310
- Debugger . Break ( ) ;
305
+ Debug . WriteLine ( formattedException . ToString ( ) ) ;
311
306
312
- App . Logger ? . LogError ( ex , ex ? . Message ?? "An unhandled error occurred." ) ;
313
- } ) ;
307
+ // Please check "Output Window" for exception details (View -> Output Window) (CTRL + ALT + O)
308
+ Debugger . Break ( ) ;
314
309
315
310
// Save the current tab list in case it was overwriten by another instance
316
- SafetyExtensions . IgnoreExceptions ( SaveSessionTabs ) ;
311
+ SaveSessionTabs ( ) ;
312
+ App . Logger ? . LogError ( ex , ex ? . Message ?? "An unhandled error occurred." ) ;
317
313
318
314
if ( ! showToastNotification )
319
315
return ;
320
316
321
- SafetyExtensions . IgnoreExceptions ( AppToastNotificationHelper . ShowUnhandledExceptionToast ) ;
322
-
323
317
SafetyExtensions . IgnoreExceptions ( ( ) =>
324
318
{
325
- // Restart the app
326
- var userSettingsService = Ioc . Default . GetRequiredService < IUserSettingsService > ( ) ;
327
- var lastSessionTabList = userSettingsService . GeneralSettingsService . LastSessionTabList ;
328
-
329
- if ( userSettingsService . GeneralSettingsService . LastCrashedTabList ? . SequenceEqual ( lastSessionTabList ) ?? false )
330
- {
331
- // Avoid infinite restart loop
332
- userSettingsService . GeneralSettingsService . LastSessionTabList = null ;
333
- }
334
- else
335
- {
336
- userSettingsService . AppSettingsService . RestoreTabsOnStartup = true ;
337
- userSettingsService . GeneralSettingsService . LastCrashedTabList = lastSessionTabList ;
338
-
339
- // Try to re-launch and start over
340
- MainWindow . Instance . DispatcherQueue . EnqueueOrInvokeAsync ( async ( ) =>
341
- {
342
- await Launcher . LaunchUriAsync ( new Uri ( "files-uwp:" ) ) ;
343
- } )
344
- . Wait ( 100 ) ;
345
- }
319
+ AppToastNotificationHelper . ShowUnhandledExceptionToast ( ) ;
346
320
} ) ;
347
321
322
+ // Restart the app
323
+ var userSettingsService = Ioc . Default . GetRequiredService < IUserSettingsService > ( ) ;
324
+ var lastSessionTabList = userSettingsService . GeneralSettingsService . LastSessionTabList ;
325
+
326
+ if ( userSettingsService . GeneralSettingsService . LastCrashedTabList ? . SequenceEqual ( lastSessionTabList ) ?? false )
327
+ {
328
+ // Avoid infinite restart loop
329
+ userSettingsService . GeneralSettingsService . LastSessionTabList = null ;
330
+ }
331
+ else
332
+ {
333
+ userSettingsService . AppSettingsService . RestoreTabsOnStartup = true ;
334
+ userSettingsService . GeneralSettingsService . LastCrashedTabList = lastSessionTabList ;
335
+
336
+ // Try to re-launch and start over
337
+ MainWindow . Instance . DispatcherQueue . EnqueueOrInvokeAsync ( async ( ) =>
338
+ {
339
+ await Launcher . LaunchUriAsync ( new Uri ( "files-uwp:" ) ) ;
340
+ } )
341
+ . Wait ( 100 ) ;
342
+ }
348
343
Process . GetCurrentProcess ( ) . Kill ( ) ;
349
344
}
350
345
0 commit comments