• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

execute() and exception handling

 
Tmmet Johnson
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic