logo       

Re: proper handling of InterruptedException: msg#00075

java.jsr.166-concurrency

Subject: Re: proper handling of InterruptedException

The cardinal rule is: Never hide the fact that an interruption occurred.

So, your choices are:
- Throw IE yourself
- Re-set the interrupted bit (Thread.currentThread().interrupt())
- Handle the interruption

The classes in JUC (like BlockingQueue and Semaphore) throw IE since
their caller is in a better position to deal with the interruption than
they are.

Lots more detail in JCiP Ch 7.

Moran Avigdor wrote:
> A question arose, your opinions are welcome -
>
> What is considered a proper handling of InterrupedException?
> Is it a common practice to throw InterruptedException when the thread
> was interrupted while waiting?
> or should the thread catch it, ignore it and gracefully die?
>
> Thank you.
>


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise