Forums Register Login

InterruptedException handling

+Pie Number of slices to send: Send
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"?
+Pie Number of slices to send: Send
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

 
+Pie Number of slices to send: Send
Thank you tony. That answers my question.

I think once i am done with the tutorial topic, my immediate next stop should be JLS.
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 834 times.
Similar Threads
InterruptedException
Database Thread Safety, pls review
sleeping state
TwoThreads problem with exception
Valid Statement
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:05:08.