I basically do the same thing as Paul. My business objects throw 
their own exceptions, which I can catch. These exception classes 
are "chained" and often include more than one message: the initial 
cause and my business explanation. I use the ActionError class to 
send this to the JSP. Since they ActionError can handle a queue of 
messages, I start with a generic "Oops" message, followed by the 
more specific business error, followed by the geek-speak initial 
cause. This way everybody is happy!

ActionErrors errors = new ActionErrors();
ModelResult modelResult = null;

try {
    modelResult = getResult(
        mapping,form,request,response,helpers);
}
catch (ModelException e) {
        // Log and print to error console
    servlet.log("Model Exception: ", e );
    e.printStackTrace();
        // General error message
    errors.add(ActionErrors.GLOBAL_ERROR,
        new ActionError("error.general"));
        // Generate error messages from exceptions
    errors.add(ActionErrors.GLOBAL_ERROR,
        new ActionError("error.detail",e.getMessage()));
    if (e.isCause()) {
        errors.add(ActionErrors.GLOBAL_ERROR,
            new ActionError("error.detail",e.getCauseMessage()));
    }
}

The "error.detail" is one big replacement parameter

error.detail={0}

Then I look for an input mapping, and use that for the error 
page if there is one. If not, I look for a generic "error" page instead. 

// -- Report any errors
if (!errors.empty()) {
    saveErrors(request, errors);
    if (mapping.getInput()!=null)
        return (new ActionForward(mapping.getInput()));
    // If no input page, use error forwarding
    return (mapping.findForward(Tokens.ERROR));
}

The chained exception class is based on Brian Goetz' class. 

http://www.javaworld.com/javaworld/jw-08-2001/jw-0803-exceptions.html

-Ted.

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to