How to store printStackTrace into a string
Something along the lines of
StringWriter errors = new StringWriter();
ex.printStackTrace(new PrintWriter(errors));
return errors.toString();
Ought to be what you need.
Relevant documentation:
- StringWriter
- PrintWriter
- Throwable
Guava makes this easy with Throwables.getStackTraceAsString(Throwable):
Exception e = ...
String stackTrace = Throwables.getStackTraceAsString(e);
Internally, this does what @Zach L suggests.