public static String getStackTrace(Throwable t)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
t.printStackTrace(pw);
pw.flush();
sw.flush();
return sw.toString();
}
Monday, June 15, 2009
Print Stack Trace to String object
Stack trace is essential in finding errors in your program, but printing stack trace to standard output might not be what we always want. This simple method will buffer the stack trace print output to String object.