Proposal: Improved Exception Handling for Java

Stephen Colebourne scolebourne at joda.org
Tue Mar 3 00:54:39 PST 2009


Neal Gafter wrote:
>> What happens if someone writes
>>
>>   catch(final IOException | SomeSubclassOfIOException e) {...}
>>
>> In other words, is it legal to have subclasses of a caught exception listed
>> too?
> 
> I don't really care one way or the other.  As written, yes, it is
> allowed and means the same thing as the supertype alone.

I would continue to allow this in the spec. It means that if someone 
refactors exceptions changing the hierarchy, then another part of the 
code with a multi-catch will continue to compile and have the same meaning.

>> How could the increased exception precision be maintained will still allow
>> programs such as the one above to compile?
> 
> I don't think it can without making rather complex rules, but I'll
> think about it more.
> 
> However, one could take only the multicatch part of this proposal and
> not the final/rethrow part, and then I believe one could specify it
> without there being a breaking change.

I would prefer to see them added to Project Coin as two separate 
proposals. (I have some usability concerns with rethrow, but am OK with 
multi-catch)

Stephen



More information about the coin-dev mailing list