Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

How to log unhandled exception

$
0
0

I have following code in my Xamarin Forms project. I used SentryErrorLog to log exception and saved exception message to pp device locally. I have tested following code and the logging is successful. But I found when there is an unknown exception causing App crashed, there is no log in Sentry and in ExternalStorageDirectory. The unknown exception caused the App shutdown and popup an message "{App name} has stopped".

Because there is no log of the exception, so I don't know how to investigate it. And this exception only happens sometimes, it's hard for me to find the reason. So I want to know if I missed any code to catch the exception? Or sometimes the Android closes the App before the App triggers the exception event handler?

    public override void OnCreate()
    {
        base.OnCreate();

        ravenClient = SentryErrorLog.CreateRavenClient();
        AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironment_UnhandledExceptionRaiser;
    }

    private void AndroidEnvironment_UnhandledExceptionRaiser(object sender, RaiseThrowableEventArgs e)
    {
        ravenClient.LogException(e.Exception);
        LogExceptionLocally(e.Exception);
    }

    private void LogExceptionLocally(Exception e)
    {
        // Log to ExternalStorageDirectory
    }

Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>