Java / Android: how to view Stacktrace log

Asked

Viewed 514 times

13

How can I display the whole exception error code (Fullstacktrace) in Android Log?

try {
    //CODE
}catch (Exception e){
    Log.e(TAG,e.getStackTrace());
}   

3 answers

14


I found a very practical way that I honestly didn’t know could be done like this.

try {
    //CODE
}catch (Exception e){
    Log.e(TAG, "Seu erro: ", e);    
}
  • 1

    Simply log in the exception and no relaunch it can leave the application in an indefinite state.

  • 2

    @Luiz Carvalho your answer was very useful, if you can mark it as accepted , so when other users view your question they see that you already have a correct answer and accept it for you.

  • 1

    Done @iTSangar :D

2

You can use it as follows:

try {
  //CODE
} catch (Exception e) {

  Log.e(TAG, "log de erro: ", e.getMessage());    
  Log.v(TAG, "log de verbose: ", e.getMessage());    
  Log.d(TAG, "log de debug: ", e.getMessage());    
  Log.i(TAG, "log de info: ", e.getMessage());    
  Log.w(TAG, "log de alerta: ", e.getMessage());  
}

or

Log.e(TAG, "log de erro: ",new RuntimeException("TAG meu erro"));    

2

I wear it like this:

Log.e("TAG", Log.getStackTraceString(e));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.