cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carsten Ziegeler" <>
Subject RE: [RT] Checked exceptions considered harmful
Date Wed, 14 Apr 2004 14:26:48 GMT
Ugo Cei wrote:
> Carsten Ziegeler wrote:
> > In general I agree with Bertrand that it's nicer to add a "throws 
> > Exception" to an Interface to tell the user that something can go 
> > wrong.
> You will get to add a "throws Exception" to any method only 
> over my dead body ;-).
Be carefull with what you wish... :)

Seriously, I don't want to change any interface, but I think if an
exception can occur it's easier to say "throws Exception" than
to say "throws MySpecialException1, MySpecialException2" etc.
But at the same time, special exceptions like the ResourceNotFoundException
should be declared in the throws clause, as you might recover
from them.
So perhaps it's better to distinguish between Exceptions (that
you might recover from) and Errors. But unfortunately, the client
should be the one deciding that the exception is recoverable
and not the called component.

> > And we shouldn't forget that some exceptions are treated 
> differently, 
> > for example the ResourceNotFound exception (that's the 
> reason for the 
> > ugly exception handling code in SourceUtil). This exception 
> is treated 
> > by the sitemap engine differently from other exceptions and we 
> > shouldn't loose this feature.
> Indeed. That's why I propose that ProcessingException extends 
> CascadingRuntimeException, instead of CascadingException. 
> This way, you won't be forced to catch it (and catch 
> ResourceNotFoundException) if you don't need to and be 
> tempted to wrap it or swallow it.
> The sitemap engine can continue catching it as it does now.
> The litmus test should be the following: can you recover from 
> a ResourceNotFoundException, in the general case? IMHO, no. 
> Your best course of action is to tell the user.
> If I'm not mistaken, reparenting ProcessingException would 
> require zero changes in other components, it would be a 
> totally backward-compatible change, but could allow us to 
> remove lots of useless code. So I'm proposing to do this for 2.1.5.
Hmm, yes this change is backward-compatible but has the danger that
you simply forget to check for a recoverable exception as you don't
notice that it's thrown. Difficult.


View raw message