Here you can find the source of stackTrace(Throwable e)
Parameter | Description |
---|---|
e | A Throwable. |
public static final String stackTrace(Throwable e)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.PrintWriter; public class Main { /**/*from w ww . j a va 2 s . com*/ * Returns the output of printStackTrace as a String. * * @param e A Throwable. * @return A String. */ public static final String stackTrace(Throwable e) { String throwableAsString = null; try { // And show the Error Screen. ByteArrayOutputStream buf = new ByteArrayOutputStream(); e.printStackTrace(new PrintWriter(buf, true)); throwableAsString = buf.toString(); } catch (Exception f) { // Do nothing. } return throwableAsString; } /** * Returns the output of printStackTrace as a String. * * @param e A Throwable. * @param addPre a boolean to add HTML <pre> tags around the stacktrace * @return A String. */ public static final String stackTrace(Throwable e, boolean addPre) { if (addPre) { return "<pre>" + stackTrace(e) + "</pre>"; } else { return stackTrace(e); } } }