我最终滚动了自己的代码(我采用了Throwable.printStackTrace()的实现,并对其进行了一些调整):
public static String joinStackTrace(Throwable e) { StringWriter writer = null; try { writer = new StringWriter(); joinStackTrace(e, writer); return writer.toString(); } finally { if (writer != null) try { writer.close(); } catch (IOException e1) { // ignore } }}public static void joinStackTrace(Throwable e, StringWriter writer) { PrintWriter printer = null; try { printer = new PrintWriter(writer); while (e != null) { printer.println(e); StackTraceElement[] trace = e.getStackTrace(); for (int i = 0; i < trace.length; i++) printer.println("tat " + trace[i]); e = e.getCause(); if (e != null) printer.println("Caused by:rn"); } } finally { if (printer != null) printer.close(); }}


