Here you can find the source of printStackTraceUsingStream(Throwable throwable)
public static String printStackTraceUsingStream(Throwable throwable)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.PrintStream; public class Main { public static String printStackTraceUsingStream(Throwable throwable) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); throwable.printStackTrace(ps);/*from ww w.ja v a2s.c o m*/ return baos.toString(); } public static String printStackTrace(Throwable throwable) { StringBuilder sb = new StringBuilder(); sb.append("Caused by: ").append(throwable).append('\n'); for (StackTraceElement ste : throwable.getStackTrace()) { sb.append('\t').append(ste.toString()).append('\n'); } if (throwable.getCause() != null) { return sb.toString() + printStackTrace(throwable.getCause()); } else { return sb.toString(); } } }