Allerdings behandelt testCase2 die Ausnahme nicht und löst einen Fehler aus. Fehle ich etwas? Tut mir leid, wenn ich das tat, ziemlich neu.Erwartet die gleichen Ergebnisse von diesen beiden 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();
}
danke. Ich fühle mich so dumm. :/ – slee
Keine große Sache, nur ein häufiger Fehler, den jeder beim Lernen macht :-) – shizhz