This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Does your book have any recipes for exception handling, especially on how to use declarative exception handling, best pracices for exceptions, tips, traps etc.. Also, which one is better, programatic handling or declarative handling??
Recipe 5.4 Use declarative exception handling uses a use case to illustrate how to implement declarative exception handling. The key to implementing it well is to make sure you have a well thought out exception strategy. Its important to spend a little time to come up with an inheritance hierarchy that suits your architecture. In this recipe we illustrate a sample strategy and show how it dove tails into declarative exception handling.
It is a best practice to always create a global exception tag to catch anything that might slip through. Its a graceful way to handle the unexpected. The best practice reads as follows ...
Best Practice: Always create a global exception tag to catch java.lang.Exception
Under Struts 1.1, an Action's execute method allows an unintentional return of an exception descending from java.lang.Exception. Unless these exceptions are caught by the ExceptionHandler, the user will receive a "Server Error 500". A graceful way to handle this unexpected condition is to create a global exception tag to handle java.lang.Exception.
We also have another recipe that shows you how to deal with an aggregation of exceptions (5.5 Aggregate exceptions). Often you will want to discover as many issues up front and aggregate then into a single exception. In this recipe we show you how to roll your own ExceptionHandler to deal with an aggregation of exceptions.