In this code:
doSomethingThatMightThrowAnException()
.whenComplete((result, ex) -> doSomethingElse()})
.exceptionally(ex -> handleException(ex));
The exceptionally method states:
Returns a new CompletableFuture that is completed when this CompletableFuture completes, with the result of the given function of the exception triggering this CompletableFuture's completion when it completes exceptionally; otherwise, if this CompletableFuture completes normally, then the returned CompletableFuture also completes normally with the same value. Note: More flexible versions of this functionality are available using methods whenComplete and handle.
This is not, IMHO written in the clearest english but I would say that means that if an exception is thrown then only the exceptionally
action will be triggered. If no exception is thrown then only the normal
action will be performed.