public static Throwable unwrapThrowable ( final Throwable wrappedThrowable ) { Throwable unwrapped = wrappedThrowable ; while ( true ) { if ( unwrapped instanceof InvocationTargetException ) { unwrapped = ( ( InvocationTargetException ) unwrapped ) . getTargetException ( ) ; } else if ( unwrapped instanceof UndeclaredThrowableException ) { unwrapped = ( ( UndeclaredThrowableException ) unwrapped ) . getUndeclaredThrowable ( ) ; } else { return unwrapped ; } } }
Unwraps invocation and undeclared exceptions to real cause .