Java Exception to String exceptionToString(final Throwable throwable)

Here you can find the source of exceptionToString(final Throwable throwable)

Description

exception To String

License

Apache License

Declaration

public static String exceptionToString(final Throwable throwable) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String exceptionToString(final Throwable throwable) {
        StringBuilder result = new StringBuilder();
        Throwable cause = throwable;

        while (cause != null) {
            if (result.length() == 0) {
                result.append("\nException in thread.");
            } else {
                result.append("\nCaused by: ");
            }/*w ww.ja  va2 s  . c  o m*/
            result.append(cause.getClass().getCanonicalName()).append(": ").append(cause.getMessage());

            for (final StackTraceElement traceElement : cause.getStackTrace()) {
                result.append("\n\tat ").append(traceElement.toString());
            }
            cause = cause.getCause();
        }
        return result.toString();
    }
}

Related

  1. exception_details(Exception e, String message)
  2. exceptionFormat(E exception)
  3. exceptionStackToString(Throwable x)
  4. exceptionToString(final Exception e)
  5. exceptionToString(final Throwable ex)
  6. exceptionToString(Throwable e)
  7. exceptionToString(Throwable e)
  8. exceptionToString(Throwable ex)
  9. exceptionToString(Throwable exception)