Exception handling

Exception handling is one of the critical parts of any application. It is very important to have a consistent exception handling strategy across the application. One of the popular misconceptions is that only bad applications need exception handling. Nothing can be further from the truth. Even well-designed, well-written applications need good exception handling.

Before the emergence of the Spring Framework, exception handling code was needed across application code due to the wide use of checked exceptions. For example, most of the JDBC methods threw checked exceptions, requiring a try catch to handle the exception in every method (unless you would want to declare that the method throws a JDBC exception). With Spring Framework, most of the exceptions were made unchecked exceptions. This made sure that, unless specific exception handling was needed, exception handling could be handled generically across the application.

In this section, we will look at couple of example implementations of exception handling as follows:

  • Common exception handling across all controllers
  • Specific exception handling for a Controller
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset