Hi Paul,
> Why doesn't the Restlet framework make more use of exceptions? Why
> should I have to do something like this:
>
> if ( /* disaster */ ) {
> response.setStatus( CLIENT_ERROR_WHATEVER, "message" );
> return;
> }
>
> when I could do something like this:
>
> if ( /* disaster */ )
> throw new RestletException( CLIENT_ERROR_WHATEVER,
> "message" );
>
> if RestletException existed? Why doesn't RestletException (or
> something like it) exist?
One advantage of using the response's status is that this information is
part of the uniform interface and can easily cross the JVM boundaries
without affecting the calling code.
If we used RestletExceptions 'in addition', we could break this uniformity
("a handle method given two parameters carrying all the communication
info"), having two ways to bubble up the same information.
Another example is the fact that connectors use various types of exceptions
(Simple, Jetty, etc.) so we would loose client code portability if these
exceptions weren't converted into uniform statuses.
> If this existed, then the Message.getEntityAs*() methods could be
> declared to throw it. As it is, getEntityAsSax() catches and
> discards an IOException. That doesn't seem good.
This is indeed an edge case. In fact, the SaxRepresentation can't throw
IOException at construction time, so the constructor had a wrong signature.
I've fixed the issue in SVN trunk!
Best regards,
Jerome