File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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.
I agree. Here's the link:
subject: Error handling
It's not a secret anymore!