Java Stacktrace to String getStackTrace(Exception e)

Here you can find the source of getStackTrace(Exception e)

Description

Returns the stack trace of the given exception in a string.

License

Open Source License

Parameter

Parameter Description
e the exception

Return

String

Declaration

public static final String getStackTrace(Exception e) 

Method Source Code


//package com.java2s;
import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {
    /**//ww w . java 2  s.c o m
     * Returns the stack trace of the given exception in a string.
     * @param e the exception
     * @return String
     */
    public static final String getStackTrace(Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        return sw.toString();
    }
}

Related

  1. getStackTrace()
  2. getStackTrace()
  3. getStackTrace(Exception e)
  4. getStackTrace(Exception e)
  5. getStackTrace(Exception e)
  6. getStackTrace(Exception exception)
  7. getStackTrace(Exception x)