Here you can find the source of getStackTrace(final Throwable t)
Returns the stack trace of the given exception as a string.
Parameter | Description |
---|---|
t | The exception whose stack trace is to be unwrapped and returned as a string. |
public static String getStackTrace(final Throwable t)
//package com.java2s; //License from project: Open Source License import java.io.PrintWriter; import java.io.StringWriter; public class Main { /**/*from ww w .j a v a 2 s . c o m*/ * <p> * Returns the stack trace of the given exception as a string. * </p> * * @param t * The exception whose stack trace is to be unwrapped and * returned as a string. * @return A string representation of the exception's stack trace */ public static String getStackTrace(final Throwable t) { StringBuffer result = new StringBuffer(); try { StringWriter writeBuffer = new StringWriter(); PrintWriter printBuffer = new PrintWriter(writeBuffer); // write the stack buffer into the StringWriter t.printStackTrace(printBuffer); printBuffer.flush(); printBuffer.close(); result.append(writeBuffer.toString()); } catch (Throwable t2) { result.append("Unexpected error getting stack trace: " + t2.getMessage()); } return result.toString(); } }