Code: Select all
try {
CompletableFuture.allOf(someFuture, someOtherFuture).get();
} catch (InterruptedException | ExecutionException ex) {
Thread.currentThread().interrupt();
if (ex.getCause() instanceof CustomException customException) {
throw customException;
}
throw new CustomException(CustomErrorCodeEnum.UNEXPECTED_ERROR, ex.getCause().getMessage());
}
Aber jetzt frage ich mich, ob ich join() (das keine InterruptedException auslöst) anstelle von get() verwenden kann, ohne den Interrupt zu verschlucken (und die Informationen über den Interrupt zu verlieren). Ich möchte es z.B. nutzen. so:
Code: Select all
try {
CompletableFuture.allOf(someFuture, someOtherFuture).join();
} catch (CompletionException | CancellationException ex) {
if (ex.getCause() instanceof CustomException customException) {
throw customException;
}
throw new CustomException(CustomErrorCodeEnum.UNEXPECTED_ERROR, ex.getCause().getMessage());
}
Mobile version