• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Thread exceptions

 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ??
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
permaculture is giving a gift to your future self. After reading this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic