2

I need to integrate Firebase Crashlytics into my custom UncaughtExceptionHandler I tried the solution here, but I ended up not having my custom handler called.

This is what I originally had to use my custom handler in my MainActivity

Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));

Adding Crashlytics.logException(exception) would only result in loggin non-fatal error, while I need to log normal errors. Note: Logging with Crashlytics.logException(exception) worked only once for me so far, while it didn't appear on the dashboard many other times although the log in the IDE showed it was uploaded, even after the next app startup.

My main question: Can I log normal crash and have my own custom UncaughtExceptionHandler implemented?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441

1 Answers1

0

Fabric/Firebaser here - this is a question that definitely comes up, and it is possible to implement your own custom UncaughtExceptionHandler.

When you initialize Crashlytics, it instruments your default UncaughtExceptionHandler. What you can do is basically write a wrapper for it. You can do whatever you want with the uncaught exception, and then pass your handler through to Crashlytics. That might look like (psuedocode):

crashlyticsHandler = Thread.setDefaultUncaughtExceptionHandler()

myUncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
    void uncaughtException(Throwable e) {
        //your code here
        crashlyticsHandler.uncaughtException(e)
    }
}

Thread.setDefault(myUncaughtExceptionHandler)
Kevin Kokomani
  • 1,568
  • 7
  • 14