I'd like to log an error and throw an exception inside orElseThrow() clause. I need to prepare proper supplier:
Working code:
Optional<Integer> op = Optional.of(24832);
op.orElseThrow(() -> new RuntimeException());
How to log an error and throw an exception at once:
op.orElseThrow({
Logger.error("Incorrect value");
() -> new RuntimeException();
});