public static Throwable getCause ( Throwable e , Class < ? extends Throwable > ... causes ) { if ( ( e == null ) || ( causes == null ) || ( causes . length < 1 ) ) { return null ; } else if ( isInstance ( e , causes ) ) { if ( ( ( e . getCause ( ) == null ) || ( e . getCause ( ) . equals ( e ) || ( ! equals ( e . getClass ( ) , causes ) ) ) ) ) { return e ; } else { return getCause ( e . getCause ( ) , causes ) ; } } else if ( ( e . getCause ( ) == null ) && ( e instanceof InvocationTargetException ) ) { return getCause ( ( ( InvocationTargetException ) e ) . getTargetException ( ) , causes ) ; } else if ( e . getCause ( ) == null ) { return null ; } else { return getCause ( e . getCause ( ) , causes ) ; } }
Gets the cause which are one of the given expected causes . This method is useful when you have to find a cause within unexpected or unpredictable exception wrappings .