Java Stacktrace to String stackTraceToString(Throwable e)

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

Description

Converts a StackTraceElement array to a string.

License

Open Source License

Parameter

Parameter Description
e The exception thrown.

Return

The exception's stack trace as a string.

Declaration

public static String stackTraceToString(Throwable e) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  ww w. j av a  2 s.  co m
     * <p>
     * Converts a StackTraceElement array to a string.
     * </p>
     *
     * @param e The exception thrown.
     * @return  The exception's stack trace as a string.
     */
    public static String stackTraceToString(Throwable e) {
        StringBuilder sb = new StringBuilder();
        for (StackTraceElement element : e.getStackTrace()) {
            sb.append(element.toString());
            sb.append("\n");
        }
        return sb.toString();
    }
}

Related

  1. stackTraceToString(StackTraceElement[] stackTrace)
  2. stackTraceToString(StackTraceElement[] stackTrace, StringBuilder buf)
  3. stackTraceToString(StackTraceElement[] ste)
  4. stackTraceToString(StackTraceElement[] trace)
  5. stackTraceToString(StackTraceElement[] trace)
  6. stackTraceToString(Throwable e)
  7. stackTraceToString(Throwable e)
  8. stackTraceToString(Throwable throwable)