Java Stacktrace to String getStackTraceString(Exception e)

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

Description

Converts the supplied Exception's stack trace to a String.

License

Open Source License

Declaration

public static String getStackTraceString(Exception e) 

Method Source Code

//package com.java2s;
/*/*from w  w w  .  j a v  a  2  s .  c om*/
 * $RCSfile: ImageUtil.java,v $
 *
 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
 *
 * Use is subject to license terms.
 *
 * $Revision: 1.2 $
 * $Date: 2006/07/21 20:53:28 $
 * $State: Exp $
 */

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class Main {
    /**
     * Converts the supplied <code>Exception</code>'s stack trace
     * to a <code>String</code>.
     */
    public static String getStackTraceString(Exception e) {
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        PrintStream printStream = new PrintStream(byteStream);
        e.printStackTrace(printStream);
        printStream.flush();
        String stackTraceString = byteStream.toString();
        printStream.close();
        return stackTraceString;
    }
}

Related

  1. getStackTraceFromException(Exception _e)
  2. getStackTraceFromException(Exception e)
  3. getStackTraces()
  4. getStackTraceStr(Exception e)
  5. getStackTraceString()
  6. getStackTraceString(Exception e)
  7. stackTrace()
  8. stacktrace()
  9. stacktrace2string(StackTraceElement[] stackTraceElements)