aspose file tools
The moose likes Struts and the fly likes execute() and exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "execute() and exception handling" Watch "execute() and exception handling" New topic

execute() and exception handling

Tmmet Johnson
Ranch Hand

Joined: Nov 03, 2004
Posts: 56
I have a question.
I haver a class which extends from Struts Action class.
The execute method has been overridden as below.
What will happen if I throw an application exception from the
execute().How struts will display or treat the application exceptions thrown from execute().
I don't have the applicationexception declared in the struts-config.xml.

Thanks in advance,

Please see my code snippet below.

public ActionForward execute (ActionMapping mapping,
ActionForm form,HttpServletRequest request,
HttpServletResponse response) throws Exception
//perform database operation
int i = new DAO().getId();
if(i == 9)
throw new DataInvalidException("Data is invalid");

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In this case, Struts will send an error code 500 back to the browser, along with an ugly error message. If you don't catch an exception in your Execute() method, you should definitely register the exception as a global exception in your struts-config.xml. That way you have control over what gets displayed when the exception occurs.

Consultant, Sima Solutions
Don't get me started about those stupid light bulbs.
subject: execute() and exception handling