Android - print full exception backtrace to log

前端 未结 9 1473
萌比男神i
萌比男神i 2020-11-29 23:02

I have a try/catch block that throws an exception and I would like to see information about the exception in the Android device log.

I read the log of the mobile de

9条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 23:11

    try {
        // code that might throw an exception
    } catch (Exception e) {
        Log.e("MYAPP", "exception", e);
    }
    

    More Explicitly with Further Info

    (Since this is the oldest question about this.)

    The three-argument Android log methods will print the stack trace for an Exception that is provided as the third parameter. For example

    Log.d(String tag, String msg, Throwable tr)
    

    where tr is the Exception.

    According to this comment those Log methods "use the getStackTraceString() method ... behind the scenes" to do that.

提交回复
热议问题