File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Any recipes for Exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Any recipes for Exception handling" Watch "Any recipes for Exception handling" New topic

Any recipes for Exception handling

manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325

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??


George Franciscus
Ranch Hand

Joined: Jan 25, 2005
Posts: 32
Yes, we do. We have two.

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.

George Franciscus<br /><br /><a href="" target="_blank" rel="nofollow"></a><br /><a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: Any recipes for Exception handling
It's not a secret anymore!