我一直在关注一些CompletableFuture指南,但我无法弄清楚以下代码有什么问题:
public void function1() throws CustomException {
thingsThatCouldThrowAnException();
}
public void function2() throws CustomException {
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
otherThings();
function1();
return "text";
}).handle((result, ex) -> {
if (result != null) {
doThings();
return result;
} else {
handleException(ex);
return null;
}
});
}
我仍然得到error: unreported exception CustomException; must be caught or declared to be thrown
。我滥用CompletableFuture.handle(),还是其他的东西?谢谢!