in src/main/java/com/spotify/futures/CompletableFutures.java [292:303]
public static <T> Throwable getException(CompletionStage<T> stage) {
CompletableFuture<T> future = stage.toCompletableFuture();
if (!future.isCompletedExceptionally()) {
throw new IllegalStateException("future was not completed exceptionally");
}
try {
future.join();
return null;
} catch (CompletionException x) {
return x.getCause();
}
}