1

Possible Duplicate:
Handling InterruptedException in Java

I wonder how InterruptedException should be properly handled. What actions should be performed in catch block? Are there any circumstances when the exception should be delegated to the higher level class?

Community
  • 1
  • 1
Adam Sznajder
  • 9,108
  • 4
  • 39
  • 60
  • http://www.javaspecialists.eu/archive/Issue056.html – Gray Jun 13 '12 at 21:39
  • 1
    Unfortunately the answer to this question is "it depends". You should go off and read [this article](http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html) and see if it helps you. It is an excellent treatment of the issues around InterruptedException. – sjr Jun 13 '12 at 21:36

1 Answers1

2

The point of InterruptedException is to allow a blocking method to cancel early, when requested. The one thing you shouldn't do is nothing; don't just swallow the exception.

If you can't throw the exception from your method, calling Thread.currentThread().interrupt() is usually a good bet.

Check out Brian Goetz's article, http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html, for a good discussion on this topic. Edit: looks like somebody suggested this article already - in any case, it's a good read.

Michael Bosworth
  • 2,123
  • 18
  • 8