@ExceptionHandler
: 예외가 발생했을 때 사용하는 메소드로 지정
@ExceptionHandler
public ResponseEntity<String> handle(CustomException exception) {
return ResponseEntity.badRequest().body("CustomException");
}
→ CustomException 이 발생되면 handle 메소드가 실행됨
@ExceptionHandler
public ResponseEntity handle(RuntimeException exception) {
return ResponseEntity.badRequest().body(exception.getMessage());
}
→ RuntimeException 을 포함한 하위 클래스의 예외가 발생하면 메소드 실행