Here you can find the source of stackTraceToString(Throwable e)
public static String stackTraceToString(Throwable e)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; public class Main { public static String stackTraceToString(Throwable e) { String retValue = null;//ww w . j a v a 2 s .c om StringWriter sw = null; PrintWriter pw = null; try { sw = new StringWriter(); pw = new PrintWriter(sw); e.printStackTrace(pw); retValue = sw.toString(); } finally { try { if (pw != null) { pw.close(); } if (sw != null) { sw.close(); } } catch (IOException ignore) { } } return retValue; } }