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
posted
0
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