Java Exception Format formatException(final Exception e)

Here you can find the source of formatException(final Exception e)

Description

Formats the given exception in a multiline error message with all causes.

License

Open Source License

Parameter

Parameter Description
e Exception for format as error message

Return

Returns an error string

Declaration

public static String formatException(final Exception e) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**// w  w w. j a v a  2 s. co m
     * Formats the given exception in a multiline error message with all causes.
     * 
     * @param e
     *          Exception for format as error message
     * @return Returns an error string
     */
    public static String formatException(final Exception e) {
        final StringBuilder sb = new StringBuilder();
        Throwable t = e;
        while (t != null) {
            sb.append(t.getMessage()).append("\n");
            t = t.getCause();
        }
        return sb.toString();
    }
}

Related

  1. fmtError( Exception e )
  2. formatException(Throwable ex)
  3. formatException(Throwable exception)
  4. formatException(Throwable th)
  5. formatExceptionMsg(String msg)