public static Throwable getFailed ( CompletionStage < ? > stage ) { CompletableFuture < ? > future = stage . toCompletableFuture ( ) ; Preconditions . checkArgument ( future . isCompletedExceptionally ( ) ) ; try { future . get ( ) ; throw new AssertionError ( "future should be failed" ) ; } catch ( InterruptedException e ) { throw new AssertionError ( "Unexpected error" , e ) ; } catch ( ExecutionException e ) { return e . getCause ( ) ; } }
Get the error now when we know for sure that the future is failed .