Bird
0
0

Which of the following method signatures is valid for an exception handler in a Spring Boot controller?

easy📝 Conceptual Q2 of 15
Spring Boot - Exception Handling
Which of the following method signatures is valid for an exception handler in a Spring Boot controller?
Apublic int handleException(Exception ex, String message)
Bpublic void handleException()
Cpublic String handleException(HttpServletRequest request)
Dpublic ResponseEntity<String> handleException(NullPointerException ex)
Step-by-Step Solution
Solution:
  1. Step 1: Check method parameters

    An exception handler method typically accepts the exception type it handles as a parameter.
  2. Step 2: Check return type

    Returning ResponseEntity or a response body type is valid for sending HTTP responses.
  3. Step 3: Validate options

    public ResponseEntity handleException(NullPointerException ex) matches the expected signature with exception parameter and response return type.
  4. Final Answer:

    public ResponseEntity handleException(NullPointerException ex) -> Option D
  5. Quick Check:

    Exception parameter required [OK]
Quick Trick: Exception handler methods need exception parameter [OK]
Common Mistakes:
  • Omitting exception parameter
  • Using unrelated parameters
  • Returning primitive types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes