Java Throwable to String getStackTrace(Throwable t)

Here you can find the source of getStackTrace(Throwable t)

Description

A convenient way of extracting the stack trace from an exception.

License

Open Source License

Parameter

Parameter Description
t The <code>Throwable</code>.

Return

The stack trace as generated by the exception's printStackTrace(PrintWriter) method.

Declaration

public static String getStackTrace(Throwable t) 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    /**/*from  w  ww . ja  v  a2  s  . c o m*/
     * A convenient way of extracting the stack trace from an
     * exception.
     *
     * @param t The <code>Throwable</code>.
     * @return The stack trace as generated by the exception's
     * <code>printStackTrace(PrintWriter)</code> method.
     */
    public static String getStackTrace(Throwable t) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw, true);
        t.printStackTrace(pw);
        return sw.getBuffer().toString();
    }
}

Related

  1. getStackTrace(Throwable t)
  2. getStackTrace(Throwable t)
  3. getStackTrace(Throwable t)
  4. getStackTrace(Throwable t)
  5. getStackTrace(Throwable t)
  6. GetStacktrace(Throwable t)
  7. getStackTrace(Throwable t)
  8. getStackTrace(Throwable t)
  9. getStackTrace(Throwable t)