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; }
If you enjoyed this post, make sure you subscribe to my RSS feed!



























Related Posts:
No Responses to “Exception stackTrace to a String Variable”
Please Wait
Leave a Reply