26 Aug 2012

Exception Handling in a n-tiered Web Application

8/26/2012

Exception handling is a key although ignored aspect in any web application development. Most of the times exception handling for developers seems as simple as either catching the exception or throwing it. 

However exception handling has a much more to do and much more to add to any application. The challenge is more for any architecture if it is a n-tired web application. The approach is very simple but needs to be understood and implemented keeping key ingredients in mind.

There are some key aspects that needs to be kept in mind while modelling exception handling -
  • Every Layer has to have its own wrapper exception class. Take for example i have a standard 3 layered architecture Presentation layer, Service layer & Database (DAO / DTO layer). So the exception handling model for this would be exception wrapper class for each layer such as MyAppDatabaseException.java , MyAppServiceException.java etc.
  •  Each layer should throw wrapper exception class for that layer to the other to communicate and propagate exceptions in a bottom up model, exception chaining in other words . Ref the image below


  • Now as shown in the exception chaining model above when application exceptions are propagated from one layer to the other, the handshake occurs as they all would extend the same parent class and also have a variable errorCode, which can be used to set unique codes for different types of exception in order for them to be handled in the application layer desired.


Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

 

© 2013 NimbleGeek. All rights resevered. Designed by Templateism

Back To Top