• Post Reply Bookmark Topic Watch Topic
  • New Topic

User Defined Exception  RSS feed

 
rex antony
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we create UserDefined Exception extends CheckedException?.Is it possible?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All classes that extend Exception (either directly or indirectly) are checked exceptions, unless they also extend RuntimeException (either directly or indirectly).
So if your class extends Exception, but not RuntimeException, then it is a checked exception.
 
rex antony
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne,
For uncheckedException,Can we extends RuntimeException for the UserDefinedException.

Thanks and Regards
Rex

Joanne Neal wrote:All classes that extend Exception (either directly or indirectly) are checked exceptions, unless they also extend RuntimeException (either directly or indirectly).
So if your class extends Exception, but not RuntimeException, then it is a checked exception.
 
Rakesh Jhamb
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, you can.

All subclasses of RuntimeException are treated as Unchecked Exception.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rex antony wrote:For uncheckedException,Can we extends RuntimeException for the UserDefinedException.
Yes, but it might not be very useful.
you should find some examples in the Java™ Tutorials.
 
rex antony
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes RuntimeException comes under UnCheckedException.But what i asking that Can we create userDefinedException for UnCheckException.

Rakesh Jhamb wrote:yes, you can.

All subclasses of RuntimeException are treated as Unchecked Exception.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rex antony wrote:Yes RuntimeException comes under UnCheckedException.But what i asking that Can we create userDefinedException for UnCheckException.


Yes. You can extend RuntimeException, and the resulting class will be an unchecked exception class.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!