Search code examples
javacompletable-future

Does java completableFuture has method returning CompletionStage<U> to handle exception?


Does java completableFuture have thenCompose method having param with CompletionStage value type to handle exception? like this method:

 public <U> CompletableFuture<U> thenCompose(BiFunction<? super T, Throwable, ? extends CompletionStage<U>> var1)

I want to handle the result and exception and convert the result use a function A returning a completableFuture, just like :

CompletableFuture<V> A(V v,Throwable e); 

and function A will call RPC. It is a async function.

CompletableFuture.handle(BiFunction<? super T, Throwable, ? extends U> var1) just convert the result, can not combine two completableFuture, can not meet my needs.


Solution

  • Have you tried to chain thenCompose with handle or exceptionally?

    It should meet your needs.