Jan
17
Exception stackTrace to a String Variable
Posted by | Posted in Java | Posted on 17-01-2008
Tagged Under : Java
There is an easy an elegant way to convert or store an exception stack trace to a string variable. The following method takes an exception object as a parameter and returns the string representation of the stack trace.
public String getStackTrace(Exception ex) { java.io.StringWriter out = new java.io.StringWriter(); ex.printStackTrace(new java.io.PrintWriter(out)); String stackTrace = out.toString(); return stackTrace; } |


