Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a bad idea to use printStackTrace() for caugt Exceptions?

Is it a bad idea to use printStackTrace() in Android Exceptions like this?

} catch (Exception e) {     e.printStackTrace(); } 
like image 499
jacknad Avatar asked Oct 04 '10 12:10

jacknad


People also ask

Why is exception printStackTrace () considered bad practice?

It is not bad practice because something is 'wrong' about PrintStackTrace(), but because it's 'code smell'. Most of the time the PrintStackTrace() call is there because somebody failed to properly handle the exception.

Does printStackTrace throw exception?

The printStackTrace() method in Java is a tool used to handle exceptions and errors. It is a method of Java's throwable class which prints the throwable along with other details like the line number and class name where the exception occurred.

Should I use e printStackTrace?

e. printStackTrace() is generally discouraged because it just prints out the stack trace to standard error. Because of this you can't really control where this output goes. The better thing to do is to use a logging framework (logback, slf4j, java.

What is the output when we try to print exception using printStackTrace?

The printStackTrace() method of Java. lang. Throwable class used to print this Throwable along with other details like class name and line number where the exception occurred means its backtrace. This method prints a stack trace for this Throwable object on the standard error output stream.


1 Answers

I believe this is what you need:

catch (Exception e) {      Log.e(TAG,Log.getStackTraceString(e));  } 
like image 127
Adil Atilgan Avatar answered Sep 23 '22 01:09

Adil Atilgan