Java Throwable to Root Cause getRootCauseStackTrace(Throwable throwable)

Here you can find the source of getRootCauseStackTrace(Throwable throwable)

Description

get Root Cause Stack Trace

License

LGPL

Declaration

public static String getRootCauseStackTrace(Throwable throwable) 

Method Source Code


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

import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {
    public static String getRootCauseStackTrace(Throwable throwable) {
        Throwable rootCause = getRootCause(throwable);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        rootCause.printStackTrace(pw);/*from   w w  w  .ja  v  a2 s.  c o m*/
        return sw.toString();
    }

    public static Throwable getRootCause(Throwable throwable) {
        Throwable cause = throwable;
        while (cause.getCause() != null) {
            cause = cause.getCause();
        }
        return cause;
    }
}

Related

  1. getRootCauseStackTrace(@Nonnull final Throwable throwable)
  2. getRootStackTrace(Throwable t)