This question already has an answer here:
I want to print the stack trace because at the moment I have this running.
} catch (IOException e) {
throw new Error("Copying Failed");
}
And I have been told to print e.stacktrace();
How do I do this?
And check the LogCat for the output.
It is most likely you were requested to print the stack trace via
e.printStackTrace();
...An other method, very useful :
In Android you should use the log methods that work nicely with the Logcat log viewer used by Android.
Using the Log.e method that takes a throwable as an argument you make sure that the log class will take the stacktrace and log it correctly to Logcat. If you use e.printStackTrace this will use the general Java logging methods and it will not appear correctly in Logcat and in some cases it will not be possible to double click on a class name in logcat to jump into the class and method mentioned in the stacktrace.
Print Stacktrace for a divide by zero will look like this:
The exception is logged as a warning and the log tag is not very helpful.
Correct logging of a divide by zero will look like this:
The exception is correctly logged as an error with your log tag and log message.