Thanks Ted & Paul.
As always, a useful piece of the puzzle.
Just wondering what you need the isCause() method. I
read the article about exception handling, but when
you write the detail message -- won't this write the
cause out for you?
Where would you not have the cause?
Also: the business error -- is it the last one thrown
or the first? The cause: is this the last one thrown
or the first?
thanks,
Sandeep
--- Ted Husted <[EMAIL PROTECTED]> wrote:
> 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]>
>
__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>