get Most Specific Cause Throwable - Java java.lang

Java examples for java.lang:Throwable

Description

get Most Specific Cause Throwable

Demo Code


//package com.java2s;

public class Main {

    public static Throwable getMostSpecificCause(Throwable ex) {
        Throwable rootCause = getRootCause(ex);
        return (rootCause != null ? rootCause : ex);
    }/*from  w ww  .j a  va 2s. c  o m*/

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

Related Tutorials