Java Throwable to String getStackTrace(Throwable thrown)

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

Description

Takes a throwable and puts it's stacktrace into a string.

License

Apache License

Parameter

Parameter Description
thrown a parameter

Declaration

public static String getStackTrace(Throwable thrown) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;

public class Main {
    /**/*from   www.  j  a  va 2  s  .c o m*/
    * Takes a throwable and puts it's stacktrace into a string.
    * @param thrown
    * @return
    */
    public static String getStackTrace(Throwable thrown) {
        try {
            Writer writer = new StringWriter();
            PrintWriter printWriter = new PrintWriter(writer);
            thrown.printStackTrace(printWriter);
            return writer.toString();
        } catch (Exception exc) {
            //System.out.println("JavaRendererUtilties.getStackTrace()");
            //return "Error - couldn't retrieve stack trace";
            return "";
        }
    }
}

Related

  1. getStackTrace(Throwable throwable)
  2. getStackTrace(Throwable throwable)
  3. getStackTrace(Throwable throwable)
  4. getStackTrace(Throwable throwable)
  5. getStackTrace(Throwable throwable)
  6. getStackTraceAsByteArrayOutputStream(Throwable throwable)
  7. getStackTraceAsStr(Throwable t)
  8. getStackTraceAsString(Throwable e)
  9. getStackTraceAsString(Throwable ex)