trying out the prototype (original) (raw)

Joe Darcy joe.darcy at oracle.com
Wed Aug 25 10:08:17 PDT 2010


Gernot Neppert wrote:

2010/8/24 Joe Darcy <joe.darcy at oracle.com>:

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

What I do understand is that the exception thrown from the block is considered more important than the exception thrown by the same resource afterwards, when it is being closed. I just doubt that you can make a similarily educated guess about the relative importance of exceptions thrown by unrelated resources. Here is a simple example: try(Writer out = new FileWriter("output.txt"; Reader in = new FileReader("input.txt")) { // Code to copy from in to out. } Now, if the constructor of 'in' throws a (relatively harmless) FileNotFoundException, the much more serious DiskFullException thrown by the close() method of 'out' will be lost.

It is trivial to generate situations where any fixed policy of suppressing exceptions gives the "wrong" answer about propagating the most informative exception.

The coin-dev list has hosted longs threads speculating how try-with-resources would and would not work in practice.

We don't have to limit ourselves to speculating anymore: since there is a prototype which can be easily downloaded and run on many platforms, people can use the feature and report back how it works (or not) in practice.

-Joe



More information about the coin-dev mailing list