Spring Boot: Custom Error Handling Essentials
Explore the basics of implementing custom error handling in Spring Boot applications.
Questions in this quiz
15 questions on Spring Boot: Custom Error Handling Essentials. Work through them here, then start the quiz to answer them and see your score.
1.What annotation is used to create a custom error handler in Spring Boot?
- A@ErrorHandler
- B@ExceptionHandler
- C@ErrorAdvice
- D@ControllerAdvice
2.Which class can be used to create a global exception handler in Spring Boot?
- AControllerAdvice
- BGlobalExceptionHandler
- CExceptionHandler
- DErrorController
3.What is the purpose of the @ResponseStatus annotation in Spring Boot?
- ATo redirect requests
- BTo log errors
- CTo specify HTTP status codes
- DTo handle exceptions
4.How can you return a custom error message in a Spring Boot application?
- ABy using @RestController
- BBy using @ExceptionHandler
- CBy using @ResponseBody
- DBy using @ResponseStatus
5.What is the default error response format in Spring Boot?
- AXML
- BHTML
- CPlain text
- DJSON
6.Which method in the ResponseEntity class can be used to set a custom HTTP status?
- AwithStatus()
- Bstatus()
- CsetStatus()
- DhttpStatus()
7.What does the @RestControllerAdvice annotation do?
- AHandles exceptions globally for REST controllers
- BFormats error messages
- CRedirects error pages
- DLogs all errors
8.Which of the following is NOT a valid HTTP status code for error handling?
- A404
- B403
- C200
- D500
9.What is the role of the ErrorController interface in Spring Boot?
- ATo redirect error requests
- BTo log errors
- CTo handle all exceptions
- DTo customize error responses
10.How can you provide a custom error page for a 404 error in Spring Boot?
- AUse @ErrorPage
- BUse @ExceptionHandler
- CCreate a 404.html in resources/templates
- DModify application.properties
11.What is the purpose of the @ResponseBody annotation in error handling?
- ATo redirect requests
- BTo return error details in the response body
- CTo specify the HTTP status
- DTo log error messages
12.Which property in application.properties can be used to disable the default error page in Spring Boot?
- Aserver.error.path
- Bserver.error.include-stacktrace
- Cserver.error.whitelabel.enabled
- Dserver.error.include-message
13.What is the default path for error handling in Spring Boot?
- A/fault
- B/error
- C/exception
- D/fail
14.How can you include the stack trace in the error response in Spring Boot?
- AModify the ErrorController
- BUse @ExceptionHandler
- CSet server.error.include-stacktrace=always
- DSet server.error.path
15.Which of the following is a common practice when handling exceptions in Spring Boot?
- ARedirecting exceptions
- BSuppressing exceptions
- CLogging exceptions
- DIgnoring exceptions