Java Utililty Methods Dump Throwable

List of utility methods to do Dump Throwable

Description

The list of methods to do Dump Throwable are organized into topic(s).

Method

Stringdump(final Throwable throwable)
dump
if (throwable == null) {
    return "null";
final StringWriter sw = new StringWriter(512);
throwable.printStackTrace(new PrintWriter(sw, true));
return sw.toString();
voiddumpThrowable(final String additionalDescr, final Throwable t)
Dumps a Throwable in a decorating message including the current thread name, and its #dumpStack(PrintStream,StackTraceElement[],int,int) stack trace .
System.err.println("Caught " + additionalDescr + " " + t.getClass().getSimpleName() + ": " + t.getMessage()
        + " on thread " + Thread.currentThread().getName());
dumpStack(System.err, t.getStackTrace(), 0, -1);
int causeDepth = 1;
for (Throwable cause = t.getCause(); null != cause; cause = cause.getCause()) {
    System.err.println("Caused[" + causeDepth + "] by " + cause.getClass().getSimpleName() + ": "
            + cause.getMessage() + " on thread " + Thread.currentThread().getName());
    dumpStack(System.err, cause.getStackTrace(), 0, -1);
...
StringdumpThrowable(Throwable e)
Extracts the stack trace from the throwable to string.
if (e == null) {
    return null;
if (e.getCause() != null) {
    e = e.getCause();
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
...
StringdumpThrowable(Throwable thr)
dump Throwable
try {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(bos);
    thr.printStackTrace(ps);
    ps.flush();
    bos.flush();
    String str = bos.toString();
    ps.close();
...