trying out the prototype (original) (raw)

Gernot Neppert mcnepp02 at googlemail.com
Wed Aug 25 03:01:02 PDT 2010


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.



More information about the coin-dev mailing list