Java Exception Print printExceptionWithStackTrace(Throwable t)

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

Description

print Exception With Stack Trace

License

Apache License

Declaration

public static String printExceptionWithStackTrace(Throwable t) 

Method Source Code

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

public class Main {
    public static String printExceptionWithStackTrace(Throwable t) {
        StringBuilder sb = new StringBuilder();
        sb.append(t);/*from w w w . j av  a 2 s . c o  m*/
        sb.append("\n");
        for (;;) {
            for (StackTraceElement s : t.getStackTrace()) {
                sb.append(s.toString());
                sb.append("\n");
            }
            t = t.getCause();
            if (t == null) {
                break;
            }
            sb.append("Caused by: " + t.toString() + "\n");
        }
        return sb.toString();
    }
}

Related

  1. PrintException(StringBuilder Str, boolean HTML, Throwable T, boolean PrintCauseToo)
  2. printException(Throwable e, StackTraceElement[] trace)
  3. printExceptionInfo(Exception e)
  4. printExceptionMessage(Throwable ex)
  5. PrintExceptionMessages(StringBuilder Str, boolean HTML, Throwable T, boolean PrintCauseToo)