-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b06da5
commit 34cf6e2
Showing
4 changed files
with
75 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using Microsoft.Maui; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Dispatching; | ||
using Microsoft.Maui.Graphics; | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace BlazorBindings.Maui | ||
{ | ||
public static class ErrorPageHelper | ||
{ | ||
public static void ShowExceptionPage(Exception exception) | ||
{ | ||
Debug.WriteLine($"Fatal exception caught: '{exception?.GetType().Name}': '{exception?.Message}'"); | ||
|
||
Application.Current.Dispatcher.DispatchAsync(() => | ||
{ | ||
Application.Current.MainPage = GetErrorPageForException(exception); | ||
}); | ||
} | ||
|
||
private static ContentPage GetErrorPageForException(Exception exception) | ||
{ | ||
var errorPage = new ContentPage() | ||
{ | ||
BackgroundColor = Colors.White, | ||
Title = "Unhandled exception", | ||
Content = new StackLayout | ||
{ | ||
Margin = new Thickness(0, top: 30, 0, 0), | ||
Padding = 10, | ||
Children = | ||
{ | ||
new Label | ||
{ | ||
TextColor = Colors.Black, | ||
FontAttributes = FontAttributes.Bold, | ||
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), | ||
Text = "Unhandled exception", | ||
}, | ||
new Label | ||
{ | ||
TextColor = Colors.Black, | ||
Text = exception?.Message, | ||
}, | ||
new ScrollView | ||
{ | ||
Content = | ||
new Label | ||
{ | ||
TextColor = Colors.Black, | ||
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), | ||
Text = exception?.StackTrace, | ||
}, | ||
|
||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
return errorPage; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters