相关疑难解决方法(0)

从CompletableFuture抛出异常

我有以下代码:

// How to throw the ServerException?
public void myFunc() throws ServerException{
    // Some code
    CompletableFuture<A> a = CompletableFuture.supplyAsync(() -> {
        try {
            return someObj.someFunc();
        } catch(ServerException ex) {
            // throw ex; gives an error here.
        }
    }));
    // Some code
}
Run Code Online (Sandbox Code Playgroud)

someFunc()抛出一个ServerException.我不想在这里处理这个问题,而是将异常抛给someFunc()调用者myFunc().

java exception-handling exception java-8 completable-future

25
推荐指数
2
解决办法
4万
查看次数