Jun 7, 2017

Exception handling in Spring boot

  1. Overview
  2. Controller layer Exception propagation
  3. Service layer Exception propagation
  4. Exception handler
This post will illustrate Exception handling / propagation with Spring for RESTful API / WebServices

Controller layer Exception propagation

In Spring if we need to handle or build an error response then we need to map / create a corresponding exception class and throw that class eventually.

Service layer Exception propagation

Subsequently we can throw the Exception in the lower layer that is in the service layer which eventually propagated the controller class, which is shown in the upper layer.

Exception handler

We can create different type of Exception such as NotFoundException (404), BadRequestException (400), AuthorizationException (401), ServiceConditionException (503), SystemException (500) and then eventually handle that exception in a separate class in a more centralized way.


The code can be checked out / downloaded from github repository: Exception Propagation