Java Exception Message exception(Throwable t)

Here you can find the source of exception(Throwable t)

Description

Constructs a pretty one line version of a Throwable .

License

Open Source License

Parameter

Parameter Description
t the Throwable to format.

Return

a string representing information about the

Declaration

public static String exception(Throwable t) 

Method Source Code

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

public class Main {
    /**/*from   w ww  .  ja  v  a2 s. c o m*/
     * Constructs a pretty one line version of a {@link Throwable}. Useful for
     * debugging.
     *
     * @param t the {@link Throwable} to format.
     * @return a string representing information about the {@link Throwable}
     */
    public static String exception(Throwable t) {
        // TODO: We should use clear manually written exceptions
        StackTraceElement[] trace = t.getStackTrace();
        return t.getClass().getSimpleName()
                + " : "
                + t.getMessage()
                + ((trace.length > 0) ? " @ "
                        + t.getStackTrace()[0].getClassName() + ":"
                        + t.getStackTrace()[0].getLineNumber() : "");
    }
}

Related

  1. exception(Throwable e)
  2. exceptionMessage(Object... strings)
  3. exceptionMessage(Throwable e)
  4. exceptionSimpleDesc(final Exception e)
  5. exceptionStackTrace(Exception ex)