I went through this tutorial to learn about Firebase crash reporting. This is the code I've written to use it:
FirebaseApp.initializeApp(this);
try {
throw new FileNotFoundException();
} catch (FileNotFoundException ex) {
FirebaseCrash.logcat(Log.ERROR, TAG, "NPE caught");
String exception=ex.toString();
FirebaseCrash.report(ex);
}
In my Firebase console I can see my error. Everything is working perfect but I have one question. Is there any way to catch any exception wherever it occurs?
Firebase Crash Reporting will capture any Exception that does not get explicitly caught and crashes your app. You don't have to worry about that. Those are marked as Fatal exceptions in the dashboard. Exceptions you report are marked as non-fatal.
As a general rule, you should not try to suppress all exceptions, in order to prevent your app from crashing. Some exceptions indicate an unrecoverable situation or programming error, and your app process really should go away in order to prevent things from getting worse. Attempting to change this behavior could be worse for your users than seeing the Android crash dialog.