Код: Выделить всё
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());
}
Но теперь мне интересно, могу ли я использовать join() – который не генерирует InterruptedException – вместо get(), не проглатывая прерывание (таким образом теряя информацию о прерывании). Я хотел бы использовать это так (например):
Код: Выделить всё
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());
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... terruption
Мобильная версия