Avoiding use of ExceptionUtils

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…

Published by

lekkim

Positive, competent, out-spoken, frank and customer focused architect and developer with a strong foundation in web, cloud and product development. I'm a strong advocate for API first and cloud based solutions and development. I have a knack for being able to communicate and present technically complicated matters in conference, customer and training settings. I've previously acted as team member and leader in a product organisation.