For a long time for error reporting I have been using Apache Commons Lang to convert a stacktrace to a string (Avoiding use of org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(Throwable)) but for a project I was fixing up today the dependency was overkill since it was the only thing I used. A simple replacement is:
StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); String stack_trace = sw.getBuffer().toString();
Commons Lang is still very much in my arsenal since it has utility methods to so many nice to have functions…