1
但是,testCase2不处理异常并引发错误。我错过了什么吗?对不起,如果我这样做,这是相当新的。期望从这两个CompletableFutures获得相同结果
@Test
public void testCase1() throws Exception {
CompletableFuture.supplyAsync(() -> {
if (true) throw new RuntimeException();
return "Promise";
}).exceptionally((ex) -> {
return "Fake Promise";
}).get();
}
@Test
public void testCase2() throws Exception {
CompletableFuture<String> cf = CompletableFuture.supplyAsync(() -> {
if (true) throw new RuntimeException();
return "Promise";
});
cf.exceptionally((ex) -> {
return "Fake Promise";
});
cf.get();
}
谢谢。我感到很愚蠢。 :/ – slee
没有什么大不了的,只是每个人在学习时都会犯的一些常见错误:-) – shizhz