Tag Archives: stacktrace

Convert Java stacktrace to String

stacktrace
To present java stacktrace as string use next snippet:

Exception e = new Exception("EX!");

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);

String stacktraceAsString = sw.toString();

Thanx to http://stackoverflow.com/a/1149712