public static void unwrapAndThrow ( Throwable ex ) { if ( ex instanceof RuntimeException ) throw ( RuntimeException ) ex ; else if ( ex instanceof Error ) throw ( Error ) ex ; else if ( ex instanceof ExecutionException ) unwrapAndThrow ( ex . getCause ( ) ) ; else throw new UndeclaredThrowableException ( ex ) ; }
Properly unwraps ExecutionException throwing the relevant original cause . Otherwise RuntimeExceptions get thrown and checked exceptions get wrapped in a RuntimeException .