The following code snippet, which invokes thenCombine, does not set an exception at whenComplete (it prints No exception
):
CompletableFuture.completedFuture(true)
.thenCombine(CompletableFuture.completedFuture(true),
(x,y) -> {
return CompletableFuture.failedStage(new RuntimeException());
})
.whenComplete( (myVal, myEx) -> {
if (myEx == null) {
System.out.println("No exception");
} else {
System.out.println("There was an exception");
}
});
However, the similar code below, which invokes thenCompose, does set an exception:
CompletableFuture.completedFuture(true)
.thenCompose(
x -> {
return CompletableFuture.failedStage(new RuntimeException());
})
.whenComplete( (myVal, myEx) -> {
if (myEx == null) {
System.out.println("No exception");
} else {
System.out.println("There was an exception");
}
});
Why is thenCombine
returning a normally-completed CompletionStage
when its BiFunction is actually returning a failed stage?