public static < ResultT , ExceptionT extends Exception > ResultT getAndHandleExceptions ( Future < ResultT > future , Function < Throwable , ExceptionT > exceptionConstructor ) throws ExceptionT { Preconditions . checkNotNull ( exceptionConstructor ) ; try { return Exceptions . handleInterruptedCall ( ( ) -> future . get ( ) ) ; } catch ( ExecutionException e ) { ExceptionT result = exceptionConstructor . apply ( e . getCause ( ) ) ; if ( result == null ) { return null ; } else { throw result ; } } }
Calls get on the provided future handling interrupted and transforming the executionException into an exception of the type whose constructor is provided .