trying out the prototype

Joshua Bloch jjb at google.com
Wed Aug 25 11:06:39 PDT 2010


David,

I very much disagree with this one.  I see it as a major win that you don't
end up with multiple levels of indentation.

         Josh

On Tue, Aug 24, 2010 at 4:14 AM, David Holmes <David.Holmes at oracle.com>wrote:

> Gernot Neppert said the following on 08/24/10 19:27:
> > 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 ;-)
>
> I tend to agree the syntax is awkward and far less readable than simply
> nesting the try-with statements.
>
> David Holmes
>
> > Here's an example:
> >
> > class ThrowsOnRead extends Reader
> > {
> >     public int read(char[] cbuf, int off, int len) throws IOException
> >    {
> >       throw new IOException();
> >    }
> >
> >       @Override
> >       public void close() throws IOException
> >        {
> >
> >        }
> > }
> >
> > class ThrowsOnClose extends Reader
> > {
> >     public void close() throws IOException
> >    {
> >      throw new IOException();
> >    }
> >
> >     public int read(char[] cbuf, int off, int len) throws IOException
> >    {
> >      return 0;
> >    }
> > }
> >
> >
> >
> > public class TestAutoClose {
> >
> >       public static void main(String[] args) throws IOException {
> >               try(Reader rdr1 = new ThrowsOnRead(); Reader rdr2 = new
> ThrowsOnClose())
> >               {
> >                   rdr1.read();  // Why is this exception more important
> than the
> > one thrown by rdr2.close() ?
> >               }
> >       }
> > }
> >
>
>



More information about the coin-dev mailing list