| 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
|
|
|