1.

How Spring boot application handle the runtime exception internally and what are the annotation to use to declare the user define exception? Any real time scenario where spring boot fit to handle the exception.

Answer»

Spring boot checks if any CLASS is annotated as @ControllerAdvice and @ExceptionHandler and called from rest end point layer, when any exception occurs than spring boot calls the corresponding annotated class to handle the error MESSAGE.

  • Spring boot provides the below annotation to create the CUSTOM handler which eventually catch the exception from rest endpoint.
  • Spring boot provides the cross-cutting concern to handle the exception being generated by rest layer.
  • Leverage to use the error message CODE comprehensively. 
  • @ControllerAdvice is an annotation, to handle the exceptions globally.
  • @ExceptionHandler is an annotation used to handle the specific exceptions and sending the custom responses to the client.

The real-time scenario is like, let’s say that most of the exception message is system generated and has a straightforward information, which is sometimes difficult to interpret by the user interface and understand by layman user, to solve this issue spring boot handle the error message and convert into the meaningful and comprehensive message which easy to understand and interpret. 



Discussion

No Comment Found