| Author |
InterruptedException handling
|
Rakesh K. Cherukuri
Ranch Hand
Joined: Jun 01, 2010
Posts: 47
|
|
When a thread supports InterruptedException, it can stop what it is doing currently and come to an end. This is well documented in java tutorial.
However, when talking about throwing the InterruptedException the documentation says
In more complex applications, it might make more sense to throw an InterruptedException:
if (Thread.interrupted()) {
throw new InterruptedException();
}
This allows interrupt handling code to be centralized in a catch clause.
Am i correct in saying "in cases where the InterruptedException is thrown, the exception handler will always be part of the same thread"?
|
Warm Regards,
Rakesh
|
 |
Tony Docherty
Bartender
Joined: Aug 07, 2007
Posts: 1161
|
|
Exception handling is executed by the thread that encountered the exception. The JLS says
If no catch clause that can handle an exception can be found, then the current thread (the thread that encountered the exception) is terminated. Before termination, all finally clauses are executed and the uncaught exception is handled according to the following rules:
If the current thread has an uncaught exception handler set, then that handler is executed.
Otherwise, the method uncaughtException is invoked for the ThreadGroup that is the parent of the current thread. If the ThreadGroup and its parent ThreadGroups do not override uncaughtException, then the default handler's uncaughtException method is invoke
|
 |
Rakesh K. Cherukuri
Ranch Hand
Joined: Jun 01, 2010
Posts: 47
|
|
Thank you tony. That answers my question.
I think once i am done with the tutorial topic, my immediate next stop should be JLS.
|
 |
 |
|
|
subject: InterruptedException handling
|
|
|