Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not catching unwrapCfException #291

Open
huhaosumail opened this issue Dec 20, 2024 · 0 comments
Open

can not catching unwrapCfException #291

huhaosumail opened this issue Dec 20, 2024 · 0 comments
Labels
✨ feature New feature

Comments

@huhaosumail
Copy link
Member

huhaosumail commented Dec 20, 2024

目前Cffu提供的catching方法可以比CompletableFuture的exceptionally方法更细化的针对准确类型的非包装类的异常进行细节处理。但是入参必须是已经从CompletableFuture转为Cffu的实例。

Cffu failed = cffuFactory.failedFuture(new IndexOutOfBoundsException());
System.out.println(CompletableFutureUtils.catching(failed,RuntimeException.class, ex -> 2).get());
System.out.println(CompletableFutureUtils.catching(failed,IndexOutOfBoundsException.class, ex -> 3).get());

但是入参如果是一个未被转化的CompletableFuture异常,该异常会被包装,在此情形下能否兼容处理呢?

CompletableFuture failed = CompletableFuture.supplyAsync(()->{
    throw new IndexOutOfBoundsException();
});
System.out.println(CompletableFutureUtils.catching(failed,RuntimeException.class, ex -> 2).get());
System.out.println(CompletableFutureUtils.catching(failed,IndexOutOfBoundsException.class, ex -> 3).get());

可以参考Guava的catching能够准确处理

ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
ListenableFuture listenableFuture = executorService.submit(()->{
  throw   new UnsupportedOperationException("s");
});
System.out.println(Futures.catching(listenableFuture,RuntimeException.class, ex -> 2).get());
System.out.println(Futures.catching(listenableFuture,IndexOutOfBoundsException.class, ex -> 3).get());
@oldratlee oldratlee added the ✨ feature New feature label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature New feature
Development

No branches or pull requests

2 participants