Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #738

Re: TeeOutputStream?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Stanimir Stamenkov <s7an10@netscape.net>
Newsgroups comp.lang.java.help
Subject Re: TeeOutputStream?
Date Sun, 05 Jun 2011 10:44:47 +0300
Organization A noiseless patient Spider
Lines 41
Message-ID <isfc5f$jcm$1@dont-email.me> (permalink)
References <YVzGp.501$_I7.309@newsfe08.iad>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Sun, 5 Jun 2011 07:44:47 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="VdcnnljfizG2LUdZ5iOA6g"; logging-data="19862"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185XBcHoIrnbNcL1vP+RYF+"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20110531 SeaMonkey/2.1pre
In-Reply-To <YVzGp.501$_I7.309@newsfe08.iad>
X-Face )>>ChyF_H<b)u~Zjgo/=wa~;=qyW%.F\L.d^fKL[;y\=tY\]M}2t(a^;PKS}9g|k@\vkA<P Q|4?kcJ52334f:CaCrQZ=]D~txPPh6[y{xHkZ+4/KPKZ~|*K#?EqeP0W]iU*Ldy-hyjh0)N4c.I<m) K}GsUUe0)~24Xp`Jt
Cancel-Lock sha1:X7Tv/B51OTrXe6Rm2afL+AWRifY=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.help:738

Show key headers only | View raw


Sat, 04 Jun 2011 17:17:04 -0700, /Knute Johnson/:

> public void close() throws IOException {
>      try {
>          os1.close();
>      } finally {
>          os2.close();
>      }
> }
>
> This guarantees that both close() methods will get called.  If both
> methods throw IOExceptions the caller will never see the first one as it
> will be hidden.

I usually do:

     boolean success = false;
     try {
         os1.close();
         success = true;
     } finally {
         try {
             os2.close();
         } catch (IOException ex) {
             if (success) {
                 throw ex;
             }
             // Log 'ex' possibly as warning to look at
             // subsequent error logs for details (about
             // the "original" exception).
         }
     }

Yes it looks messy.  Java 7 promises to bring improvement in that 
area with try-with-resources (auto-closeable resources) and 
exception masking:

http://www.oracle.com/technetwork/articles/java/trywithresources-401775.html

-- 
Stanimir

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

TeeOutputStream? Knute Johnson <nospam@knutejohnson.com> - 2011-06-04 17:17 -0700
  Re: TeeOutputStream? Roedy Green <see_website@mindprod.com.invalid> - 2011-06-04 22:18 -0700
  Re: TeeOutputStream? Stanimir Stamenkov <s7an10@netscape.net> - 2011-06-05 10:44 +0300
  Re: TeeOutputStream? rossum <rossum48@coldmail.com> - 2011-06-05 12:23 +0100
    Re: TeeOutputStream? Stanimir Stamenkov <s7an10@netscape.net> - 2011-06-06 01:23 +0300
      Re: TeeOutputStream? Patricia Shanahan <pats@acm.org> - 2011-06-05 16:55 -0700
        Re: TeeOutputStream? Stanimir Stamenkov <s7an10@netscape.net> - 2011-06-07 00:45 +0300
      Re: TeeOutputStream? rossum <rossum48@coldmail.com> - 2011-06-06 15:16 +0100
  Re: TeeOutputStream? markspace <-@.> - 2011-06-06 14:08 -0700
  Re: TeeOutputStream? Henk van Voorthuijsen <voorth@gmail.com> - 2011-06-08 03:31 -0700
    Re: TeeOutputStream? Knute Johnson <nospam@knutejohnson.com> - 2011-06-08 16:11 -0700

csiph-web