CompletableFuture already completed with an exception

Unlike Java 9 and later, Java 8 does not provide a static factory method for this scenario. The default constructor can be used instead:

CompletableFuture<T> future = new CompletableFuture<>();
future.completeExceptionally(exception);

Leave a Comment