Skip to content

Commit 3237118

Browse files
committed
fix: catch all exceptions in the suspending handler
1 parent a7aa966 commit 3237118

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

Screenbox/App.xaml.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,28 @@ void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
250250
private async void OnSuspending(object sender, SuspendingEventArgs e)
251251
{
252252
SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();
253-
SentrySdk.AddBreadcrumb("Suspending", category: "lifecycle");
254-
var tasks = WeakReferenceMessenger.Default.Send<SuspendingMessage>().Responses;
255-
if (!string.IsNullOrEmpty(Secrets.SentryDsn))
253+
try
256254
{
257-
// Sentry Cloud is more reliable, so we can afford to wait a bit longer to flush events
258-
// If it's a self-hosted Sentry instance, we just drop the events instead of risking delaying suspension
259-
var sentryTimeout = TimeSpan.FromSeconds(Secrets.SentryDsn.Contains("sentry.io") ? 2 : 0.5);
260-
tasks.Append(SentrySdk.FlushAsync(sentryTimeout));
261-
}
255+
SentrySdk.AddBreadcrumb("Suspending", category: "lifecycle");
256+
var tasks = WeakReferenceMessenger.Default.Send<SuspendingMessage>().Responses;
257+
if (!string.IsNullOrEmpty(Secrets.SentryDsn))
258+
{
259+
// Sentry Cloud is more reliable, so we can afford to wait a bit longer to flush events
260+
// If it's a self-hosted Sentry instance, we just drop the events instead of risking delaying suspension
261+
var sentryTimeout = TimeSpan.FromSeconds(Secrets.SentryDsn.Contains("sentry.io") ? 2 : 0.5);
262+
tasks.Append(SentrySdk.FlushAsync(sentryTimeout));
263+
}
262264

263-
await Task.WhenAll(tasks);
264-
deferral.Complete();
265+
await Task.WhenAll(tasks);
266+
}
267+
catch (Exception)
268+
{
269+
// pass
270+
}
271+
finally
272+
{
273+
deferral.Complete();
274+
}
265275
}
266276

267277
private Frame InitRootFrame()

0 commit comments

Comments
 (0)