0
0
Spring Bootframework~20 mins

ResponseEntityExceptionHandler in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ResponseEntityExceptionHandler Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does ResponseEntityExceptionHandler handle exceptions?

Consider a Spring Boot controller that throws a MethodArgumentNotValidException. How does ResponseEntityExceptionHandler respond by default?

AIt returns a 404 Not Found error without any body.
BIt returns a 500 Internal Server Error with a generic message.
CIt returns a 400 Bad Request with a detailed error body explaining validation failures.
DIt ignores the exception and lets the request succeed.
Attempts:
2 left
💡 Hint

Think about what HTTP status code is appropriate for invalid input.

📝 Syntax
intermediate
2:00remaining
Correct override of handleHttpMessageNotReadable

Which method signature correctly overrides handleHttpMessageNotReadable in a class extending ResponseEntityExceptionHandler?

Apublic ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request)
Bprotected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request)
Cprotected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request)
Dprotected ResponseEntity<Object> handleHttpMessageNotReadable(Exception ex, HttpHeaders headers, HttpStatusCode status, WebRequest request)
Attempts:
2 left
💡 Hint

Check the exact parameter types and access modifier in the superclass method.

🔧 Debug
advanced
2:00remaining
Why does custom exception handler not get called?

You created a class extending ResponseEntityExceptionHandler and annotated it with @ControllerAdvice. But your custom handleMethodArgumentNotValid method is never called. What is the most likely cause?

AThe method signature does not exactly match the superclass method signature.
BThe exception is not thrown by any controller method.
CYou forgot to add <code>@ExceptionHandler</code> annotation on the method.
DThe class is missing <code>@RestControllerAdvice</code> annotation instead of <code>@ControllerAdvice</code>.
Attempts:
2 left
💡 Hint

Check method signatures carefully when overriding methods.

state_output
advanced
2:00remaining
What is the HTTP status code returned by default for UnsupportedMediaTypeException?

When a controller receives a request with an unsupported media type, and ResponseEntityExceptionHandler handles HttpMediaTypeNotSupportedException, what HTTP status code is returned by default?

A406 Not Acceptable
B400 Bad Request
C500 Internal Server Error
D415 Unsupported Media Type
Attempts:
2 left
💡 Hint

Think about the meaning of the status codes related to media types.

🧠 Conceptual
expert
3:00remaining
Why extend ResponseEntityExceptionHandler instead of using @ExceptionHandler alone?

In Spring Boot, what is the main advantage of extending ResponseEntityExceptionHandler in your @ControllerAdvice class compared to only defining @ExceptionHandler methods?

AIt provides default handling for many common Spring MVC exceptions, reducing boilerplate code.
BIt forces all exceptions to return HTTP 200 status.
CIt disables the default Spring Boot error page and replaces it with a blank response.
DIt automatically logs all exceptions without extra code.
Attempts:
2 left
💡 Hint

Think about what ResponseEntityExceptionHandler already implements for you.