QuizzesSpring Boot: Basics of Exception Handling and Error Responses
beginner
spring

Spring Boot: Basics of Exception Handling and Error Responses

A beginner's quiz on handling exceptions and creating error responses in Spring Boot applications.

15 minutes 15 questions Pass at 70%
Time Limit
15 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

15 questions on Spring Boot: Basics of Exception Handling and Error Responses. Work through them here, then start the quiz to answer them and see your score.

  1. 1.What annotation is used in Spring Boot to handle exceptions globally across all controllers?

    • A@ControllerAdvice
    • B@RestController
    • C@ExceptionHandler
    • D@ResponseStatus
  2. 2.Which annotation is used to map a specific exception to a method in Spring Boot?

    • A@PathVariable
    • B@ExceptionHandler
    • C@RequestMapping
    • D@ResponseBody
  3. 3.What is the purpose of the @ResponseStatus annotation in Spring Boot?

    • ATo map URLs to methods
    • BTo handle database transactions
    • CTo define a controller
    • DTo set the HTTP status code for a response
  4. 4.How can you return a custom error message in a Spring Boot application?

    • ABy using @ResponseBody
    • BBy throwing an exception
    • CBy using @RequestMapping
    • DBy using @ExceptionHandler with a custom response
  5. 5.Which class can be extended to create a custom exception in Spring Boot?

    • AException
    • BThrowable
    • CRuntimeException
    • DError
  6. 6.What is the default HTTP status code for a successful request in Spring Boot?

    • A500 Internal Server Error
    • B200 OK
    • C404 Not Found
    • D400 Bad Request
  7. 7.In Spring Boot, what does the @RestController annotation imply?

    • AIt sets the HTTP status
    • BIt handles exceptions
    • CIt combines @Controller and @ResponseBody
    • DIt maps URLs to methods
  8. 8.Which HTTP status code is typically used to indicate a resource was not found?

    • A404 Not Found
    • B500 Internal Server Error
    • C200 OK
    • D403 Forbidden
  9. 9.What is the role of the ResponseEntity class in Spring Boot?

    • ATo map URLs to methods
    • BTo define a controller
    • CTo represent the entire HTTP response
    • DTo handle exceptions
  10. 10.How can you specify a custom HTTP status code in a Spring Boot response?

    • AUsing @PathVariable
    • BUsing @RestController
    • CUsing @RequestMapping
    • DUsing ResponseEntity
  11. 11.Which annotation is used to indicate that a method parameter should be bound to a web request parameter?

    • A@RequestHeader
    • B@RequestParam
    • C@PathVariable
    • D@RequestBody
  12. 12.What HTTP status code is commonly used for a bad request error?

    • A200 OK
    • B404 Not Found
    • C500 Internal Server Error
    • D400 Bad Request
  13. 13.Which annotation is used to bind a method parameter to a URI template variable?

    • A@RequestParam
    • B@RequestBody
    • C@RequestHeader
    • D@PathVariable
  14. 14.What is the purpose of the @RequestBody annotation in Spring Boot?

    • ATo map URLs to methods
    • BTo handle exceptions
    • CTo bind the HTTP request body to a method parameter
    • DTo set the HTTP status
  15. 15.Which HTTP status code indicates an internal server error?

    • A200 OK
    • B404 Not Found
    • C400 Bad Request
    • D500 Internal Server Error