I have following defined in
I'm really do not care how about struts handles an exception. Using old raw code from 1.2 generally when overriding a RequestProcesor
, I should probably replace the two methods - process and processException
. First thing is happy about catching exception from the request after processValidation
has been made. The fragment of code could look like
Exception exception = null;
if (needValidation)
try {
if (! processValidate(request, response, form, mapping)) {
return;
}
exception = (Exception)request.getAttribute(Globals.EXCEPTION_KEY);
} catch (InvalidCancelException ex) {
exception = ex;
}
ActionForward forward;
// Check out if exception occurred
if (exception != null){
forward = processException(request, response, exception, form, mapping);
The second is pretty easy if you have configured the errors forward. The errors forward is usually one of the global forwards that easily found from the mapping. Once it found, it likes to display your error message on the page. I think those would probably enough for processing an exception
exception.printStackTrace();
log.error(exception);
request.setAttribute("error", exception.getMessage());
return mapping.findForward("error");
It has been done because validate method from ActionForm
or ValidatorForm
doesn't throw any exceptions and I couldn't properly override this method without throwing some. Once thrown, who will care about it?!