Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #18912
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | markspace <-@.> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Interrupted exception chaining |
| Date | Tue, 25 Sep 2012 08:33:05 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 49 |
| Message-ID | <k3sirj$5of$1@dont-email.me> (permalink) |
| References | <d203b18b-61ce-439e-9b1f-9cf056c1d161@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Tue, 25 Sep 2012 15:33:07 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="61282af8d6595e8d991edb5ac03d6e00"; logging-data="5903"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FPCkHIuq96wUaGltZzlaiMFT26Gihv0A=" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 |
| In-Reply-To | <d203b18b-61ce-439e-9b1f-9cf056c1d161@googlegroups.com> |
| Cancel-Lock | sha1:RzVX1othyuo28ipsAUfMcJQUiZI= |
| Xref | csiph.com comp.lang.java.programmer:18912 |
Show key headers only | View raw
On 9/25/2012 3:25 AM, raphfrk@gmail.com wrote:
> Is there a recommended way of "chaining" interrupted exceptions?
I mostly agree with Eric. You shouldn't suppress interrupts unless you
must. If for example you are implementing a Runnable, you can't throw
InterruptedException but must deal with it somehow. Then catching an
interrupted exception is reasonable.
In this case however it's 100% your code and you could throw
InterruptedException. That would defeat the purpose of the code you
show, of course, but then that is also our point: what you are doing is
rather questionable.
There's no standard pattern for this because it's not done. I'd say the
closest we have to to use a finally block to make certain the interrupt
flag is restored.
/** A questionable method: wait without throwing InterruptedException. */
public void uninterruptableWait(Object c) {
boolean interrupted = false;
try {
synchronized(c) {
for(;;) {
try {
c.wait();
return;
} catch(InterruptedExcpetion ex ) {
interrupted = true;
}
}
}
} finally {
if(interrupted == true ) Thread.currentThread().interrupt();
}
}
> If that interrupt was unexpected, and causes a stack trace, then it
> would be nice if it could include the details from the thrown
> exception.
If you really need the details of the exception but can't throw from
your local use site, I'd say wrapping the exception in a
RuntimeExcpetion and throwing that is best. (Exception don't ever
throwing RuntimeException; subclass it and throw your specific exception.)
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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