wood burning stoves 2.0*
The moose likes Java in General and the fly likes Thread exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Thread exceptions" Watch "Thread exceptions" New topic
Author

Thread exceptions

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
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 ??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread exceptions