Re: Checked Exceptions
Eric Sosman <esosman@ieee-dot-org.invalid> wrote:
The value of this escapes me. It seems you're not suggesting
a new capability, but just a new syntax for an existing capability:
[SNIP]
All you've saved is one call to logFooBarError -- or have I
missed something?
Not really -- as suggested it's just syntactic sugar that makes it
easier to see which exceptions are grouped together and handled in
the same way. It would be more useful if we could place statements
before and after the case statements, but I can't think of a syntax
that doesn't get messy.
This syntax isn't very nice, but just to illustrate the idea:
while( resource == null ) {
try {
resource = aquireResource( address );
}
catch( ResourceException ex )
before: {
noErrors = noErrors + 1;
log.trace( noErrors + ". error while trying to aquire resource:" + ex.getMessage( ) );
}
case MalformedAddressException: /* Fall through */
case NoSuchHostException: /* Fall through */
case AuthorisationException: {
log.info( "Failed to resolve the address " + address + ", moving on to the next, if any." );
address = getNextAddress( );
if( address == null ) {
throw new MyInitException( "No working address." );
}
break;
}
case ImportantException: {
log.warn( "NB!: ", ex );
break;
}
case CriticalException: {
throw new MyInitException( "Bad thing happened!", ex );
}
default: {
log.debug( "Other ResourceException occured: ", ex );
}
after: {
if( noErrors > MAX_ERRORS ) {
throw new MyInitException( "Too many errors." );
}
}
} // end catch
} // end while
--
Leif Roar Moldskred