Proposal to enhance the basic try-with-resources translation

Alex Buckley alex.buckley at oracle.com
Mon Jan 11 18:12:51 UTC 2016


On 1/10/2016 2:34 AM, Anthony Vanelverdinghe wrote:
> I would like to propose an enhanced translation for the basic
> try-with-resources statement (
> https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.20.3.1
> ), such that:
>
> - there's a possibility that #suppressedExc suppresses #primaryExc,
> governed by the following precedence rule: Error > RuntimeException >
> checked Exception
> So e.g. if #suppressedExc is an Error and #primaryExc is an IOException,
> then it's the Error that will be thrown with the IOException as its
> suppressed Throwable. The motivation for this, is allowing Errors and
> RuntimeExceptions to "blow up" the program. In my experience, it's rare
> for exception-handling code to check the suppressed Throwables and act
> accordingly. So this effectively means that suppressed Errors /
> RuntimeExceptions are typically handled the same way as their
> suppressing (checked) exceptions.

The intent of suppressed exceptions was precisely that exceptions from 
resource closing do not blow up the program, and should be viewed as 
subsidiary to an exception thrown by the try block. As such, this is not 
an enhanced translation of try-with-resources, but rather a redesign. It 
is not behaviorally compatible with Java SE 7/8.

Alex


More information about the compiler-dev mailing list