java - why we cannot rethrow InterruptedException in the Runnable? -


from article below , says " @ least, whenever catch interruptedexception , don't rethrow it, reinterrupt current thread before returning.".

my question why don't rethrow interruptedexception or cannot rethrow runnable ? http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html

you can rethrow interruptedexception, checked exception, if (1) have outer catch block deal or (2) current method allowed throw given exception type, e.g. void read() throws ioexception.

a method overrides runnable.run() not allowed throw exceptions, can rethrow interruptedexception in first case:

@override public void run() {     try {         // logic         try {             // logic throws interruptedexception         } catch (interruptedexception e) {             // here can either rethrow "e"             // dealt in outer catch block or             // reinterrupt current thread             throw e;         }     } catch (interruptedexception e) {         // here cannot rethrow "e"         // have deal or         // reinterrupt current thread     } } 

Comments

Popular posts from this blog

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -