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 (wodurch die Informationen über den Interrupt verloren gehen). Ich würde es gerne so verwenden (zum Beispiel):
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