Android - print full exception backtrace to log

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

    e.printStackTrace() prints it to me. I don't think you're running the logcat correctly. Don't run it in a shell, just run

    /home/dan/android-sdk-linux_x86/tools/adb logcat

    0 讨论(0)
  • 2020-11-29 23:31
    try{
                ...
    } catch (Exception e) {
         Log.e(e.getClass().getName(), e.getMessage(), e.getCause());
    }
    
    0 讨论(0)
  • 2020-11-29 23:31

    In the context of Android, I had to cast the Exception to a String:

    try {
        url = new URL(REGISTRATION_PATH);
        urlConnection = (HttpURLConnection) url.openConnection();
    } catch(MalformedURLException e) {
        Log.i("MALFORMED URL", String.valueOf(e));
    } catch(IOException e) {
        Log.i("IOException", String.valueOf(e));
    }
    
    0 讨论(0)
提交回复
热议问题