Bird
0
0

Which Spring Boot annotation is commonly used to handle exceptions globally and return custom HTTP responses?

easy📝 Conceptual Q2 of 15
Spring Boot - Exception Handling
Which Spring Boot annotation is commonly used to handle exceptions globally and return custom HTTP responses?
A@Service
B@RestController
C@ControllerAdvice
D@Entity
Step-by-Step Solution
Solution:
  1. Step 1: Identify annotation for global exception handling

    @ControllerAdvice allows centralized exception handling across controllers.
  2. Step 2: Confirm it returns custom HTTP responses

    It can catch exceptions and customize HTTP status and body.
  3. Final Answer:

    @ControllerAdvice -> Option C
  4. Quick Check:

    Global exception handler annotation = @ControllerAdvice [OK]
Quick Trick: Use @ControllerAdvice for global exception handling [OK]
Common Mistakes:
  • Using @RestController for exception handling
  • Confusing @Service with exception handler
  • Trying to handle exceptions in @Entity classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes