6
대체를위한 중첩 된 try-catch에 대한 대안
객체를 검색하려고하는 상황이 있습니다. 조회가 실패하면 몇 가지 폴 백이 있으며 각각 실패 할 수 있습니다. 따라서 코드는 다음과 같습니다. try { return repository.getElement(x); } catch (NotFoundException e) { try { return repository.getSimilarElement(x); } catch (NotFoundException e1) { try { return repository.getParentElement(x); } catch (NotFoundException e2) { //can't recover throw …