Here you can find the source of printStackTraceToString(final Throwable t)
public static String printStackTraceToString(final Throwable t) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; public class Main { public static String printStackTraceToString(final Throwable t) throws IOException { try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw);) { t.printStackTrace(pw);//from w w w .j av a 2 s. com pw.flush(); sw.flush(); return sw.toString(); } } }