Here you can find the source of printStackTrace(Throwable throwable)
public static String printStackTrace(Throwable throwable)
//package com.java2s; //License from project: Apache License public class Main { 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'); }//from w w w . ja va2 s.c o m if (throwable.getCause() != null) { return sb.toString() + printStackTrace(throwable.getCause()); } else { return sb.toString(); } } }