Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: unnecessary code in Oracle example? Date: Thu, 10 Oct 2013 08:47:33 -0600 Organization: bilaterally symmetric Lines: 54 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx05.eternal-september.org; posting-host="c75a2e3068ccf6c98395286f3e40b97d"; logging-data="28254"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19QCjPvrjK/9mXxTfEiZOBq" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:Xha9wV2X9uDuZdShkGP1bYO8IXk= sha1:88f43JqXkA1oiN1XUVj6Mu+M7gM= Xref: csiph.com comp.lang.java.programmer:26291 Arivald writes: > W dniu 2013-10-10 07:47, Sebastian pisze: >> Am 10.10.2013 06:42, schrieb Arivald: >>> W dniu 2013-10-10 04:56, Jim Janney pisze: >>>> markspace writes: >>>> >>>>> On 10/9/2013 1:21 PM, Jim Janney wrote: >>>>>> Yes, in Java 7 you can have clean syntax and clean semantics. Looks >>>>>> like a win all around. >>>>>> >>>>> >>>>> For Java 5+, with varargs you could do (not compiled): >>> [...] >>>> >>>> Mmm... you're complicating the code with extra assignments and tests, >>>> just to avoid one layer of nesting. I like the version with two >>>> try-finally blocks, partly because the lexical structure reflects what's >>>> happening in the code: two independent cleanups. But the Java 7 version >>>> is better. >>>> >>> >>> I wonder how Java 7 version (try-with-resources) handle exceptions... >>> For example, if all 3 streams throw exception from close(), will it >>> guarantee to close all of them? And how to handle such exceptions? >>> >> Why don't you modify markspace's example to see for yourself, e. g. >> >> @Override >> public void close() throws IOException { >> System.out.println( "Trying to close " >> + getClass().getSimpleName()+":"+name ); >> throw new IOException("CloseError " + name); >> } >> >> Then read what the Javadocs have to say about suppressed exceptions. >> >> -- Sebastian > > > I read docs about suppressed exceptions. And of course I can run > test. But still I wonder how it should behave, if there is more than > one close-able resource, two of them raise exceptions, and there was > no exception in main block (so no suppression). > > Can anyone point me to relevant doc? Google is not very helpful. http://blog.eyallupu.com/2013/03/try-catch-resource-and.html Something to think about when reworking old code, if anyone has time for that. -- Jim Janney