Java Exception Format formatException(Throwable ex)

Here you can find the source of formatException(Throwable ex)

Description

Returns a formatted string in the java style exception format.

License

Open Source License

Parameter

Parameter Description
ex - the exception to format

Return

the specified exception ex as a formatted text

Declaration

public static String formatException(Throwable ex) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w w  w .jav  a  2s.  c  o m*/
     * <p>Returns a formatted string in the java style exception format.</p>
     * 
     * @param ex - the exception to format
     * @return the specified exception <code>ex</code> as a formatted text {@link String}
     */
    public static String formatException(Throwable ex) {
        StringBuilder sb = new StringBuilder();
        sb.append(ex.getMessage());
        sb.append("\n");
        StackTraceElement[] trace = ex.getStackTrace();
        for (int i = 0; i < trace.length; i++) {
            sb.append("\t");
            sb.append(trace[i]);
            sb.append("\n");
        }

        return sb.toString();
    }
}

Related

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