• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checked Exception.

 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a custom Exception class say "myException" whose super class is
java.lang.Exception is created ,then the compiler considers it as a checked exception. So how can i create a UnChecked Exception ?
Do i need to use this class "RuntimeException".
Super Class of RuntimeException is also "Exception" ? Can any one throw some light on this.
 
John Dell'Oso
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For custom unchecked exceptions you must subclass RuntimeException. For checked exceptions you directly subclass Exception.

Regards,
JD
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the super class of RuntimeException is also "Exception" ??
 
John Dell'Oso
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a detail that is handled by the JVM.

The rule is you subclass RuntimeException for unchecked exceptions and subclass Exception for checked exceptions.

Generally speaking, it's always best to use checked exceptions - see this:

Runtime Exceptions - The controversy

Regards,
JD
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic