Bird
0
0

Why does centralized error handling in Spring Boot often use ResponseEntity as the return type in @ExceptionHandler methods?

hard📝 Conceptual Q10 of 15
Spring Boot - Exception Handling
Why does centralized error handling in Spring Boot often use ResponseEntity as the return type in @ExceptionHandler methods?
ABecause ResponseEntity automatically retries the request on error
BBecause ResponseEntity allows setting both HTTP status and response body explicitly
CBecause ResponseEntity disables error logging by default
DBecause ResponseEntity forces the use of XML responses
Step-by-Step Solution
Solution:
  1. Step 1: Understand ResponseEntity capabilities

    ResponseEntity lets you specify HTTP status, headers, and body in one object.
  2. Step 2: Why this matters for error handling

    Centralized handlers can customize status codes and messages clearly using ResponseEntity.
  3. Final Answer:

    Because ResponseEntity allows setting both HTTP status and response body explicitly -> Option B
  4. Quick Check:

    ResponseEntity = control over status + body [OK]
Quick Trick: Use ResponseEntity to set status and body in error handlers [OK]
Common Mistakes:
  • Thinking ResponseEntity retries requests
  • Assuming it disables logging
  • Believing it forces XML responses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes