Here you can find the source of printExceptionWithStackTrace(Throwable t)
public static String printExceptionWithStackTrace(Throwable t)
//package com.java2s; //License from project: Apache License public class Main { public static String printExceptionWithStackTrace(Throwable t) { StringBuilder sb = new StringBuilder(); sb.append(t);/*from w w w . j av a 2 s . c o m*/ sb.append("\n"); for (;;) { for (StackTraceElement s : t.getStackTrace()) { sb.append(s.toString()); sb.append("\n"); } t = t.getCause(); if (t == null) { break; } sb.append("Caused by: " + t.toString() + "\n"); } return sb.toString(); } }