in src/main/java/com/spotify/futures/CompletableFuturesExtra.java [207:219]
public static Throwable getCompletedException(CompletionStage<?> stage) {
CompletableFuture<?> future = stage.toCompletableFuture();
checkCompleted(future);
if (!future.isCompletedExceptionally()) {
throw new IllegalStateException("future was not completed exceptionally");
}
try {
future.join();
throw new IllegalStateException("Unreachable");
} catch (CompletionException | CancellationException e) {
return e;
}
}