trying out the prototype

Joe Darcy joe.darcy at oracle.com
Tue Aug 24 11:50:10 PDT 2010


Gernot Neppert wrote:
> Hello,
>
> first of all I have to say that as a long-time advocate of some kind
> of ARM in Java I'm thrilled to finally see it in action!
>
> I've toyed with the latest snapshot and have 2 remarks:
>
> 1. If you initialize a Resource that can only throw on close(), you
> get a compiler error that might be confusing because the automatic
> invocation of close() is invisible to the person writing the code.
> Here's a not-so-useful example that nevertheless exhibits the
> aforementioned behaviour:
>
> try (Reader rdr = new StringReader("Some text"))
> {
> }
>
> 2. If you use multiple Resources, an exception thrown by one of them
> will suppress exceptions thrown by the 'close()' invocation of others.
> While I can see some sense in suppressing exceptions from 'close()' of
> the same instance, I cannot see why this reasoning should apply to
> other instances.
> (I guess this forms a case against the try-with-multiple-resources
> statement in general. The list of semicolon-delimited declarations
> enclosed by parentheses looks weird, anyway ;-)
> Here's an example:
>   

With N resources, there are possibly N+1 exceptions that can come out of 
the try-with-resources statement, 1 from the block itself and 1 from 
each of the close calls.  Only one of those exceptions can be the one 
which gets propagated out of the block.

As covered in the other recent thread, the first exception thrown is 
estimated to be the most informative one about what actually went wrong.

-Joe



More information about the coin-dev mailing list