Here you can find the source of stackTraceToString(Throwable cause)
public static String stackTraceToString(Throwable cause)
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.PrintStream; public class Main { public static String stackTraceToString(Throwable cause) { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream pout = new PrintStream(out); cause.printStackTrace(pout);//from www . j a v a2 s . co m pout.flush(); try { return new String(out.toByteArray()); } finally { try { out.close(); } catch (Exception e) { } } } }