Get your CodeRanch badge!*
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "execute() and exception handling" Watch "execute() and exception handling" New topic
Author

execute() and exception handling

Tmmet Johnson
Ranch Hand

Joined: Nov 03, 2004
Posts: 56
Hi,
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.


Merrill
Consultant, Sima Solutions
 
 
subject: execute() and exception handling
 
Similar Threads
struts configarations
neither action class called nor jsp page displayed
Cannot register driver
Caching of Database Access Objects's possible?
Struts 13.8 + Exception Handeling Problem