35
7
|
Is it a bad idea to use printStackTrace() in Android Exceptions like this?
|
||
add a comment
|
22
|
Yes, it is a bad idea. You should instead use Android's built-in log class specifically designed for these purposes: http://developer.android.com/reference/android/util/Log.html It gives you options to log debug messages, warnings, errors etc. |
||
26
|
I believe this is what you need:
|
|||
Log.e(TAG, "Explanation of what was being attempted when the exception was thrown", e)
. Note the third parameter. Log.e(String,String,Throwable) gets the stacktrace string from the Throwable for you. Use themessage
parameter for something meaningful. – spaaarky21 Jun 20 '14 at 23:27android.util.Log.e()
. I didn't learn that from any of the other answers. (I didn't click the link in Nailuj's answer.) – AndreKR May 5 '16 at 16:56Log
in an unusual way – using aLog
instance (I assume?) and passing the level in as a parameter. I added an answer. – spaaarky21 May 5 '16 at 18:09