Forums Register Login

Thread exceptions

+Pie Number of slices to send: Send
Why is it that Interrupted exception is a checked exception whereas the IllegalThreadStateException is a runtime exception.

I feel both should have been runtime exception ??
+Pie Number of slices to send: Send
IllegalThreadStateException is only thrown because of programming errors - the programmer forgot to put the call in a synchronized block / method for the object that wait, notify etc is called on. InterruptedException is, like IOException and SQLException, caused by a situation the programmer can do little about. They cannot be prevented by adding checks etc.

The general convention is:
- unchecked exceptions can be prevented by adding checks. NullPointerException, IllegalArgumentException, NoSuchElementException, in 99.99% of the cases these can be prevented (e.g. by checking against null etc).
- checked exceptions are caused by an external influence. This could be the hard disk, network, but also user interaction in the case of interrupting.

There are of course cases where exceptions don't follow this convention (CloneNotSupportedException is one of these...) but you'll see that most exceptions follow this convention.
You may have just won ten million dollars! Or, maybe a 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 744 times.
Similar Threads
Is it "Exception at runtime" or "Compile Fails" for this one?
method overriding
Exam Lab Question
Java ranch rules roundup
Exception
More...

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