Re: Container Independence

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 11 Apr 2007 15:50:38 +0200

Dhanji R. Prasanna wrote:
> On 4/11/07, *Paul Sandoz* <
> <>> wrote:
> It is intended to be thrown by the application when it wants to return
> an HTTP error response, for example:
> throw new WebApplicationException(500);
> // an enum would be better than 500 :-)
> ok that makes much more sense now. Yep, should definitely be an enum.
> But let's not have subclasses for each status code, please!


> I've no objection to static factories, however:
> throw WAE.newNotFoundException ();
> throw WAE.newForbiddenException();
> The application will use HttpResponse if it needs to return a
> representation as the body of the HTTP error response.
> Does that help explain the rational?
> Ok that makes sense--it is looking a lot nicer than I first thought =)
> Do you have any idea about how this will work in a servlet container?
> A webapp can configure a custom error page for each type of error, how
> would this work if custom content were returned? Just thinking ahead...

Good question (a developer playing with SWDP had a similar question).

It all depends on where WebApplicationException is caught. In our impl
it is caught by the runtime and not the container so it is never
propagated to the container. If it was propagated then i suppose the
container could do something meaningful with it.

The temporary solution we ended up with (which is kind if hacky) is for
the developer to throw their own runtime exception, which would get
propagated to the container.

IMHO the whole area of exceptions needs some careful thought as it is
really tricky to get right.


| ? + ? = To question
    Paul Sandoz