Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What makes RuntimeException and its sub classes unchecked??  RSS feed

 
Shreyas Dange
Greenhorn
Posts: 16
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi .,

I've read that java.lang.Exception ,except RuntimeException and Error and their subclasses all Exception classes provide a category of compiler checked exceptions and if we create a custom Exception by extending Exception class our resulting class is again a Exception that will be compiler checked , but if we create exception class by extending RuntimeException or any of its subclasses the resulting exception class is an UNCHECKED exception.

can anyone plzz tell me what it is in RuntimeException class which gives its sub classes the unchecked exception behaviour.??

Thanks..
 
Tim Cooke
Marshal
Posts: 4044
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Tutorial on Exceptions should tell you all you need to know about the different types of Exception.

You can also download the source for you favourite JDK and see how it's implemented too.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not something in the class that makes the difference. It's just that the compiler knows to treat them differently.

Probably . As Tim says, you could check the source code to be sure. Fundamentally it doesn't matter, though. The Java Language Specification states which exceptions are unchecked, so the JDK can implement that however it wants as long as it meets the spec.
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shreyas Dange wrote:
can anyone plzz tell me what it is in RuntimeException class which gives its sub classes the unchecked exception behaviour.??

Thanks..


I am not sure I understand. I think the fact that a certain RuntimeException is subclassing RuntimeException gives it the IS-A RuntimeException behaviour, i.e the unchecked exception behaviour. Or did you mean something else?

Edit : Right. After reading Matthew Brown's response, I get your question. His is the relevant answer.
 
Shreyas Dange
Greenhorn
Posts: 16
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankyou tim and matthew
got your point..!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!