Capturing Java Stacktrace as a String
August 9th, 2008
Here is a little code snippet for a method that will capture an Exception’s stacktrace as a string so you can output it on the command line or in a simple log statement.
Categories: Java
log4j Logger has a method that takes Throwable as one of the arguments and prints the stacktrace. So this is no longer necessary if you are using log4j.
http://logging.apache.org/log4j/1.2/apidocs/index.html
This is true, however, I have been on at least one clients site where they refused to use Log4j and had rolled their own logging mechanism which was not able to handle Throwables. It is also amazing how many people do not pass the throwable to log4j and those the stacktrace. it makes it very hard to debug later on without that information in the log file.
Thanks! Saved me some time figuring that out today. Damn java io classes!