Bird
0
0

How can you combine ResponseEntityExceptionHandler with @ControllerAdvice to handle multiple exception types with different HTTP statuses in one class?

hard📝 Application Q9 of 15
Spring Boot - Exception Handling
How can you combine ResponseEntityExceptionHandler with @ControllerAdvice to handle multiple exception types with different HTTP statuses in one class?
AUse only @ControllerAdvice without extending ResponseEntityExceptionHandler and handle exceptions manually.
BExtend ResponseEntityExceptionHandler, annotate with @ControllerAdvice, and add multiple @ExceptionHandler methods for different exceptions.
CCreate separate classes for each exception type without extending ResponseEntityExceptionHandler.
DOverride only handleExceptionInternal and ignore other exception methods.
Step-by-Step Solution
Solution:
  1. Step 1: Understand combining global exception handling

    Extending ResponseEntityExceptionHandler provides default handlers; @ControllerAdvice enables global scope.
  2. Step 2: Add multiple @ExceptionHandler methods

    Each method handles a specific exception with custom HTTP status, all in one class.
  3. Final Answer:

    Extend ResponseEntityExceptionHandler, annotate with @ControllerAdvice, and add multiple @ExceptionHandler methods for different exceptions. -> Option B
  4. Quick Check:

    Combine extension + @ControllerAdvice + multiple handlers = C [OK]
Quick Trick: Use @ControllerAdvice + extend + multiple @ExceptionHandler methods [OK]
Common Mistakes:
  • Splitting handlers into many classes unnecessarily
  • Not extending ResponseEntityExceptionHandler loses defaults
  • Overriding only one method limits handling

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes