Java Throwable to String getStackTrace(Throwable e)

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

Description

Gets a stack trace for an exception.

License

Open Source License

Parameter

Parameter Description
e The exception

Declaration


public static String getStackTrace(Throwable e) 

Method Source Code

//package com.java2s;
/*   Please see the license information at the end of this file. */

import java.io.*;

public class Main {
    /**   Gets a stack trace for an exception.
     *//  ww  w.  ja v a  2s.c  o  m
     *   @param e   The exception
     */

    public static String getStackTrace(Throwable e) {
        ByteArrayOutputStream traceByteArrayStream = new ByteArrayOutputStream();

        PrintStream tracePrintStream = new PrintStream(traceByteArrayStream);

        e.printStackTrace(tracePrintStream);

        tracePrintStream.flush();

        return traceByteArrayStream.toString();
    }
}

Related

  1. getStackTrace(final Throwable throwable)
  2. getStackTrace(Throwable aThrowable)
  3. getStackTrace(Throwable aThrowable)
  4. getStackTrace(Throwable e)
  5. getStackTrace(Throwable e)
  6. getStackTrace(Throwable ex)
  7. getStackTrace(Throwable ex)
  8. getStackTrace(Throwable ex)
  9. getStackTrace(Throwable exc)