Implementing 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 require exception handling. Nothing can be further from the truth. Even well-designed, well-written applications require good exception handling.

Before the emergence of Spring Framework, exception handling code was required 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 rendered 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 a 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