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.
The moose likes Struts and the fly likes Error handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Error handling" Watch "Error handling" New topic

Error handling

A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
Hi all I have my application working pretty well - in a good portion thanks to help from all of you. I am now getting database connections in place and pulling data from the db instead of using test data. My question is what is the best practice for error handling for any of the errors that can come from the db such as the sqlException or Exception. What would make sense - throwing the error, and if the caller receives an error to call an error page ?

thanks in advance.
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181

Start at 18.7 Exception handling - Struts way.

The best practice would be to use a mix of declarative exception handling and non-declarative exception handling.

For example, you may want to use declarative exception handling to handle exeptions if the database cannot be connected. You would not want to use declarative exception handling when validating user entered values (i.e. an entered value must be a number).

Another option (but probably not the best practice for struts) is to have all of your classes extend the org.apache.struts.action.Action class (which they should do already) and override the execute method and handle all of you exceptions in there.
Have you checked out Aspose?
subject: Error handling
It's not a secret anymore!