CompletableFuture
Dec 28, 2020
handle error
- default
if we do not do anything.
on calling get(), join() throw exception which wraps the actual exception as the root cause exception. - Using exceptionally() method
CompletionStage<T> exceptionally(Function<Throwable,? extends T> fn)
if there no exception. this stage is skipped otherwise it is executed
supplyAsync(…).exceptionally(… lambda or method ref) - Async exception handling (exceptionallyAsync() — java 12)
- Composing Exceptionally (exceptionallyCompose() — java 12)
- Using handle() method
handle(..), handleAsync(..)
this method is always executed regardless of exception occurs or not.
so have to handle error is null or not