I want to test Firebase Crashlytics. I can test recording non-fatal crash using RecordException
but I want to know the behavior when it actually crashes. However when I intentionally throw an exception, Blazor/the WebView handles it instead. I even tried to run it on the MainThread:
#if ANDROID
MainThread.BeginInvokeOnMainThread(() =>
{
throw new NotSupportedException("This is an error");
});
#endif
Still somehow the ErrorBoundary
is still able to catch it.
How do I throw an exception that should crash a MAUI Hybrid app? In both Android and iOS if possible.
I found one way for Android is to simply put it in the MainActivity
. Unfortunately I do not know the equivalent code for iOS but I guess I can also put the code in MainPage.xaml
as well:
public class MainActivity : MauiAppCompatActivity
{
protected override async void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
await Task.Delay(5000);
throw new Exception("This is intentional");
}
}
The crash was successfully reported.