aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Exception" Watch "Exception" New topic
Author

Exception

Hans
Greenhorn

Joined: Sep 20, 2000
Posts: 11
Question:
I design an exception MyException is abstract subclass of Exception.
Exception
|
|_MyException(abstract class)
|
|_MyException1(not abstract class)

If I code a method Do().I think I can not throw MyException As
Do() throws MyException{}
If Do throw MyException1.I know I can delclare as
Do() throws MyException1{}
Whether I can declare as
Do() throws MyException{}.?Why?
Thank you.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12271
    
    1
Exceptions follow a hierarchy just like every other object.
Of course you can declare that a method throws the abstract parent of your custom class. Why didn't you just write a test case and compile it?
You can't declare that a method throws a checked exception and then have the method throw an exception that is the parent of what you declared. Try it and see.
Bill

Java Resources at www.wbrogden.com
 
 
subject: Exception
 
Similar Threads
"Handle or Declare" Rule for Checked Exceptions
Exception handling throw and throws
exceptions - handle or declare rule
Concept on coding for Exception Handling
Exceptions doubt