/** * A way to get the entire nested stack-trace of an throwable. * * The result of this method is highly dependent on the JDK version * and whether the exceptions override printStackTrace or not. * * @param throwable The {@code Throwable} to be examined. * @return The nested stack trace, with the root cause first. */ public static String getFullStackTrace(Throwable throwable) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw, true); Throwable[] ts = getThrowables(throwable); for (Throwable t : ts) { t.printStackTrace(pw); if (isNestedThrowable(t)) break; } return sw.getBuffer().toString(); }