<aside> 1️⃣ 모든 예외처리를 한번에 모아서 하는방법

</aside>

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = {Exception.class})
    public ResponseEntity<Object> handleGenericException(Exception e) {
        // 여기서 처리하려는 모든 예외 유형을 추가합니다.
        // 예외에 대한 자세한 정보를 로깅합니다.
        // ResponseEntity 객체를 생성하고 커스텀 오류 메시지와 함께 반환합니다.
        // 일반적으로 오류 코드, 오류 메시지, 예외 유형 등을 포함하는 커스텀 오류 응답 클래스를 만들어 사용합니다.

        Map<String, Object> body = new LinkedHashMap<>();
        body.put("timestamp", new Date());
        body.put("message", e.getMessage());

        return new ResponseEntity<>(body, HttpStatus.INTERNAL_SERVER_ERROR);
    }
    
    // 특정 예외 유형을 처리하려면 새로운 메소드를 만들고 @ExceptionHandler 어노테이션을 추가합니다.
    @ExceptionHandler(value = {IllegalArgumentException.class})
    public ResponseEntity<Object> handleIllegalArgumentException(IllegalArgumentException e) {
        Map<String, Object> body = new LinkedHashMap<>();
        body.put("timestamp", new Date());
        body.put("message", e.getMessage());

        return new ResponseEntity<>(body, HttpStatus.BAD_REQUEST);
    }
}

<aside> 2️⃣ throws Exception 과 @Controller Advice 사용의 차이점

</aside>