본문 바로가기

카테고리 없음

Exception Handler

반응형

Exception Handler 란?

@Controller, @RestController의 예외를 하나의 메서드에서 처리해주는 기능!

기존의 Custom Exception은 각각의 Controller에 적용해야 했었다.

 

02 Exception Handler

@GetMapping("/read/diaries")
List<Diary> readDiaries(~~
}
@PutMapping("/update/diary")
void updateDiary(~~
}
@ExceptionHandler()
ResponseEntity<ErrorResponse> handleLineException(~~~
}

@ExceptionHandler(InvalidDate.class) // 해당 클래스에만 적용도 가능!
ResponseEntity<ErrorResponse> handleLineException(final
InvalidDate.class error) {~~
}

 

 

ControllerAdvice 

-> 모든 Controller 단을 대상으로 하여 예외가 발생한 것을 잡아줌.