Using try/catch for preventing app from crashes

前端 未结 14 2168
你的背包
你的背包 2021-01-30 03:37

I have been working on an Android app which uses try/catch frequently to prevent it from crashing even on places where there is no need. For example,

A view

14条回答
  •  忘掉有多难
    2021-01-30 04:37

    We pretty use much your same logic. Use try-catch to prevent production apps from crashing.

    Exceptions should be NEVER ignored. It is a bad coding practice. The guys maintaining the code will have a really hard time localizing the part of code that raised the exception if they are not logged.

    We use Crashlytics to log the exceptions. The code will not crash (but some functionality will be disrupted). But you get the exception log in the dashboard of Fabric/Crashlytics. You can look at these logs and fix the exceptions.

    try {
        codeThatCouldRaiseError();
    } catch (Exception e) {
        e.printStackTrace();
        Crashlytics.logException(e);
    }
    

提交回复
热议问题