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


Groups > comp.lang.java.programmer > #18945

Re: Interrupted exception chaining

From Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Interrupted exception chaining
Date 2012-09-26 16:26 +0200
Organization A noiseless patient Spider
Message-ID <k3v3b2$7tu$1@dont-email.me> (permalink)
References <d203b18b-61ce-439e-9b1f-9cf056c1d161@googlegroups.com> <k3tfih$3q5$1@dont-email.me> <k3ue44$ftk$1@news.albasani.net> <k3uej3$h2g$1@news.albasani.net>

Show all headers | View raw


On 26/09/2012 10:32, Jan Burse allegedly wrote:
> Jan Burse schrieb:
>>> a) When catching an InterruptedException, always, always call
>>> Thread.currentThread().interrupt() in the catch block. Always. Unless
>>> you know what you're doing.
>>
>> No
> 
> Mh, yes. Catch it at the right moment, outside your loop.
> And yes Thread.currentThread().interrupt() isn't the worst.
> 
> And don't forget all your I/O can also be interrupted, so
> you have to watch as well the following exception:
> 
>     InterruptedIOException
>     http://docs.oracle.com/javase/1.4.2/docs/api/java/io/InterruptedIOException.html
> 
> 
> But it usually goes unrecognized or ripples down, since
> it is a subclass of IOException. Also the bytesTransferred
> doesn't work well, especially if the stream is wrapped.

The point, which I believe you're missing, is that when you catch the
InterruptedException, the thread's interrupted status is _cleared_.
Normally, you don't want to lose that information (to wit, that it's
been interrupted). Unless, again, you specifically know what you're
doing. But since in my experience the overwhelming majority of
developers, even the experienced ones, are unaware of this fact, I
reckon it warrants a little vehemence.

-- 
DF.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Interrupted exception chaining raphfrk@gmail.com - 2012-09-25 03:25 -0700
  Re: Interrupted exception chaining Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-25 08:56 -0400
  Re: Interrupted exception chaining markspace <-@.> - 2012-09-25 08:33 -0700
    Re: Interrupted exception chaining Ivan Ryan <ivan.ryan@gmail.com> - 2012-09-25 09:28 -0700
      Re: Interrupted exception chaining Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-25 13:12 -0400
      Re: Interrupted exception chaining markspace <-@.> - 2012-09-25 12:00 -0700
  Re: Interrupted exception chaining Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-09-25 09:22 -0700
    Re: Interrupted exception chaining Jan Burse <janburse@fastmail.fm> - 2012-09-25 22:26 +0200
      Re: Interrupted exception chaining markspace <-@.> - 2012-09-25 13:37 -0700
        Re: Interrupted exception chaining Jan Burse <janburse@fastmail.fm> - 2012-09-25 22:47 +0200
          Re: Interrupted exception chaining Jan Burse <janburse@fastmail.fm> - 2012-09-25 22:53 +0200
            Re: Interrupted exception chaining Jan Burse <janburse@fastmail.fm> - 2012-09-25 22:53 +0200
          Re: Interrupted exception chaining markspace <-@.> - 2012-09-25 14:08 -0700
            Re: Interrupted exception chaining Jan Burse <janburse@fastmail.fm> - 2012-09-25 23:23 +0200
              Re: Interrupted exception chaining Jan Burse <janburse@fastmail.fm> - 2012-09-25 23:24 +0200
              Re: Interrupted exception chaining Jan Burse <janburse@fastmail.fm> - 2012-09-25 23:32 +0200
            Re: Interrupted exception chaining Jan Burse <janburse@fastmail.fm> - 2012-09-25 23:42 +0200
              Re: Interrupted exception chaining Jan Burse <janburse@fastmail.fm> - 2012-09-25 23:48 +0200
              Re: Interrupted exception chaining Jan Burse <janburse@fastmail.fm> - 2012-09-25 23:55 +0200
                Re: Interrupted exception chaining markspace <-@.> - 2012-09-25 15:33 -0700
      Re: Interrupted exception chaining Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-25 21:43 -0400
  Re: Interrupted exception chaining Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-09-26 01:43 +0200
    Re: Interrupted exception chaining Jan Burse <janburse@fastmail.fm> - 2012-09-26 10:24 +0200
      Re: Interrupted exception chaining Jan Burse <janburse@fastmail.fm> - 2012-09-26 10:32 +0200
        Re: Interrupted exception chaining Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-09-26 16:26 +0200

csiph-web