CompletableFuture

Jinhan Choi
Dec 28, 2020

handle error

  1. default
    if we do not do anything.
    on calling get(), join() throw exception which wraps the actual exception as the root cause exception.
  2. 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)
  3. Async exception handling (exceptionallyAsync() — java 12)
  4. Composing Exceptionally (exceptionallyCompose() — java 12)
  5. 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

--

--