Android - print full exception backtrace to log

前端 未结 9 1434
萌比男神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:13

    KOTLIN SOLUTION:

    You can make use of the helper function getStackTraceString() belonging to the android.util.Log class to print the entire error message on console.

    Example:

    try { 
     
       // your code here
        
    } catch (e: Exception) {
    
         Log.e("TAG", "Exception occurred, stack trace: " + e.getStackTraceString());
    
    }
    

提交回复
热议问题