You shouldn't be using e.printStackTrace()
directly anyway — doing so will send the info to the Android log without displaying which application (log tag) it came from.
As others have mentioned, continue to catch the Exception
in question, but use one of the android.util.Log
methods to do the logging. You could log only the message, but not the stack trace, or use verbose logging for the stack trace:
try {
Object foo = null;
foo.toString();
} catch (NullPointerException ex) {
Log.w(LOG_TAG, "Foo didn't work: "+ ex.getMessage());
Log.d(LOG_TAG, Util.stackTraceWriter(ex));
}
You should strip DEBUG
or VERBOSE
log messages from your production builds. The easiest way is to use ProGuard to remove Log.[dv]
calls from your code.
Util.stackTraceWriter
is not there anymore. Anyway there's thisLog.getStackTraceString
– Gelman