In MAUI Blazor (Hybrid), how do I intentionally crash the app with an exception?

76 Views Asked by At

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.

2

There are 2 best solutions below

0
Luke Vo On BEST ANSWER

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.

1
Adil Khan On

Just type 1/0 you will get crash. The exception name 1 divide by zero. Firebase Crashlytics will take time but u will get crash on it very simple.