Bird
0
0

Why might you prefer using @ControllerAdvice with @ExceptionHandler over defining @ExceptionHandler methods in each controller?

hard📝 Conceptual Q10 of 15
Spring Boot - Exception Handling
Why might you prefer using @ControllerAdvice with @ExceptionHandler over defining @ExceptionHandler methods in each controller?
AIt disables exception handling in controllers.
BIt automatically fixes all exceptions without writing code.
CIt improves application performance by skipping exception checks.
DIt centralizes exception handling, reducing code duplication and improving maintainability.
Step-by-Step Solution
Solution:
  1. Step 1: Understand purpose of @ControllerAdvice

    @ControllerAdvice allows defining exception handlers that apply across multiple controllers.
  2. Step 2: Benefits of centralized exception handling

    Centralizing reduces repeated code and makes maintenance easier.
  3. Final Answer:

    It centralizes exception handling, reducing code duplication and improving maintainability. -> Option D
  4. Quick Check:

    @ControllerAdvice centralizes exception handling [OK]
Quick Trick: Use @ControllerAdvice to centralize exception handling [OK]
Common Mistakes:
  • Thinking it auto-fixes exceptions
  • Believing it disables controller exception handling
  • Assuming it improves performance by skipping checks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes