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
Post a Comment