How to effectively group non fatal exceptions in Crashlytics (Fabrics)?

前端 未结 5 835
忘了有多久
忘了有多久 2021-01-11 19:12

We are using Crashlytics in our app as the crash reporting tool. For Android native crashes, it\'s working fine and grouping the crashes correctly. Our app also has few comp

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-11 19:24

    Crashlytics groups by the line number that the exception was generated on and labels it with the exception type. If you know all the types of the exceptions you can generate each one on a different line. And you could also map your strings to custom Exception types to make it more easy to identify them in Crashlytics.

    Here's an example:

    public void crashlyticsIsGarbage(String exceptionString) {
        Exception exception = null;
        switch(exceptionString) {
            case "string1": exception = new String1Exception(exceptionString);
            case "string2": exception = new String2Exception(exceptionString);
            case "string3": exception = new String3Exception(exceptionString);
            case "string4": exception = new String4Exception(exceptionString);
            default: exception = new Exception(exceptionString);
        }
        Crashlytics.logException(exception);
    }
    
    class String1Exception extends Exception { String1Exception(String exceptionString) { super(exceptionString); } }
    class String2Exception extends Exception { String2Exception(String exceptionString) { super(exceptionString); } }
    class String3Exception extends Exception { String3Exception(String exceptionString) { super(exceptionString); } }
    class String4Exception extends Exception { String4Exception(String exceptionString) { super(exceptionString); } }
    

    BTW, Crashlytics will ignore the message string in the Exception.

提交回复
热议问题