• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Exception

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic