I am developing a medium size Java Web Application with Struts as MVC framework and simple JDBC at Data Access Layer. I have been searching for exception handling best practices in such an application. I have found several articles, some of them being contradictory, only making me more confused rather than making things clear and simple. Some say it is better to reuse existing exceptions instead of defining application specific exceptions, others present a huge hierarchy of application specific exceptions for every minor trouble that may occur in the system. Some say it is better not to handle exceptions at Data Access Layer and delegate them to the Service Layer, others say Data Access Layer exceptions should be caught locally since delegating them to Service Layer would violate the abstraction between the two layers. And so on.
I would highly appreciate if you let me know of links/names to articles/books that present solid solutions which have worked for you in such a scenario. The solution should clear at least the following points with justifications:
- Where the SQLExceptions be caught?
- Where exceptions should be logged?
- Should unchecked exceptions be logged?
- Should unchecked exceptions be caught at presentation layer, and should they be shown to the user?
- How checked exceptions be handled, which of them to be shown to the user and how?
- How should a global exception handler page be used?
- How should struts ActionErrors be used in this context?
Thanks