Loading

Quipoin Menu

Learn • Practice • Grow

spring / Exception Handling in REST
mcq
Direction: Choose the correct option

Q1.

How can you handle exceptions in a REST controller?
A. Using @ExceptionHandler inside the controller
B. Using @ControllerAdvice globally
C. Using ResponseEntityExceptionHandler
D. All of the above
Direction: Choose the correct option

Q2.

What does @ExceptionHandler do?
A. Marks a method to handle specific exceptions thrown from controller
B. Handles global exceptions
C. Catches all exceptions
D. None
Direction: Choose the correct option

Q3.

What is @ControllerAdvice?
A. A global exception handler for multiple controllers
B. A advice for controllers
C. An aspect
D. None
Direction: Choose the correct option

Q4.

How do you return a custom error response?
A. Return ResponseEntity with error details
B. Use @ExceptionHandler with ResponseEntity
C. Create an error object
D. All of the above
Direction: Choose the correct option

Q5.

What annotation can be used with @ControllerAdvice to handle REST APIs?
A. @RestControllerAdvice
B. @ResponseBody
C. @ExceptionHandler
D. None
Direction: Choose the correct option

Q6.

What is the purpose of ResponseEntityExceptionHandler?
A. A convenient base class for @ControllerAdvice to handle Spring MVC exceptions
B. A utility class
C. An interface
D. None
Direction: Choose the correct option

Q7.

How do you handle validation errors in REST?
A. Using @Valid with BindingResult
B. Using MethodArgumentNotValidException handler
C. Both A and B
D. None
Direction: Choose the correct option

Q8.

What HTTP status code is appropriate for resource not found?
A. 404 Not Found
B. 400 Bad Request
C. 500 Internal Server Error
D. 403 Forbidden
Direction: Choose the correct option

Q9.

What status code for validation errors?
A. 400 Bad Request
B. 422 Unprocessable Entity
C. Both are used
D. None
Direction: Choose the correct option

Q10.

How do you set HTTP status on an exception class?
A. @ResponseStatus annotation on custom exception
B. Using ResponseEntity
C. Both A and B
D. None