This question already has an answer here:
Using Java 8
great feature CompletableFuture, I'd like to transform my old async code using exceptions to this new feature. But the checked exception is something bothering me. Here is my code.
CompletableFuture<Void> asyncTaskCompletableFuture =
CompletableFuture.supplyAsync(t -> processor.process(taskParam));
The signature of process
method:
public void process(Message msg) throws MyException;
How do I deal with that checked exception in ComletableFuture?
I have tried this way, but I don't know whether it's a good way to solve the problem.
With the FunctionalInterface of Supplier, I can wrap the exception: