Java Exception to String exceptionToString(Throwable e)

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

Description

Returns a String representation of Exception + stacktrace

License

Open Source License

Declaration

public static String exceptionToString(Throwable e) 

Method Source Code

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

public class Main {
    /**/*from  w w w  . java 2 s  .  co m*/
     * Returns a String representation of Exception + stacktrace
     */
    public static String exceptionToString(Throwable e) {
        return exceptionToString(e, false);
    }

    /**
     * Returns a String rep. of Exception type + stacktrace
     * @param throwable
     * @param miniStack - if true, returns only stacktrace elements w line numbers
     */
    public static String exceptionToString(Throwable throwable,
            boolean miniStack) {
        if (throwable == null)
            return "null";
        StringBuffer s = new StringBuffer(throwable + "\n");
        StackTraceElement[] stes = throwable.getStackTrace();
        for (int i = 0; i < stes.length; i++) {
            String ste = stes[i].toString();
            if (!miniStack || ste.matches(".*[0-9]+\\)"))
                s.append("    " + ste + "\n");
        }
        return s.toString();
    }
}

Related

  1. exceptionFormat(E exception)
  2. exceptionStackToString(Throwable x)
  3. exceptionToString(final Exception e)
  4. exceptionToString(final Throwable ex)
  5. exceptionToString(final Throwable throwable)
  6. exceptionToString(Throwable e)
  7. exceptionToString(Throwable ex)
  8. exceptionToString(Throwable exception)
  9. exceptionTypeAndMsg(Exception e)