Sometimes it's necessary to turn the stack trace of an exception into a String. An example would be when you are working with some home-brewed logging system that will only take a String as input. Here is a way to deal with it. The source code is HERE


public class StackTraceStringifier {

    public static String stackTraceToString(Throwable e) {
        StringWriter sw = new StringWriter();
        PrintWriter out = new PrintWriter(sw);


        return sw.toString();