Код: Выделить всё
private String getStringIfObjectIsPresent(Optional object){
object.ifPresent(() ->{
String result = "result";
//some logic with result and return it
return result;
}).orElseThrow(MyCustomException::new);
}
Подробнее здесь: https://stackoverflow.com/questions/414 ... -exception