ResponseEntityExceptionHandler에서 캐치하지 못하는 예외

조회수 213회

@Service

@Transactional
    public void getPeopleListForExport(PersonDto personDto) throws NotFoundException, IOException{
        List<Person> list = personRepository.findByPersonDto(personDto);
        exportToExcel(list);
    }

private void exportToExcel(List<Person> personList) throws IOException {
    // 코드~
}

@Controller


@PostMapping("/경로..")
    public ResponseEntity<Resource> peopleListToExcel(@RequestBody PersonDto dto) {
        personService.getPeopleListForExport(dto); /**
        --> Unhandled exception : java.io.IOException 컴파일 에러
**/

    }

@RestControllerAdvice

@RestControllerAdvice // Rest API Controller 에서 발생하는 예외를
public class CustomizeResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {

    @ExceptionHandler(Exception.class)
    public final ResponseEntity<Object> handleAllExceptions(Exception exp, WebRequest request){
        ExceptionResponse exceptionResponse = new ExceptionResponse(new Date(), exp.getMessage(), request.getDescription(false));
        return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

서비스의 private 메소드인 exportToExcel()메소드에서 IOException을 getPeopleListForExport()로 떠넘기고 getPeopleListForExport()에서 컨트롤러로 떠넘겨서 CustomizeResponseEntityExceptionHandler로 중앙에서 예외처리를 하도록 하려하는데 unhandled exception이 납니다..

왜 IOException 만 예외핸들러에서 처리할 수 없는건가요?

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)