• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Overriden exception

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why this code show error, i taught the overridding method can be sub-class of the exception of the overridden method?
 
ming ming
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry there is one more class
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is SmallFish?
Is she killed by some Exception.
Oops.. who is going to Handle the Exception thrown by test() ? (... More killing?)
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try {
a.test();
} catch (Exception e) {
// clean up
}
 
ming ming
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
smallfish juz added....

 
ming ming
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why do we want to use throws instead of throw, i still do not see any usage of throws..can anyone show me how throw can never take over the place of throws??
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
throws comes with the method signature while throw new Exception() is a statement.
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

what i found in the code that your test() method of Swim class is using throws statement. So to compile it either you remove throws statement or put try-catch block in the main method of testFish class and use throw statement in test() method's catch block. If you want your caller method shd take care of exception then use throw statement in test method.

anyone Correct me if i m wrong..

Thx,
Nitin

[ June 03, 2006: Message edited by: nitin pokhriyal ]
[ June 03, 2006: Message edited by: nitin pokhriyal ]
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
throws is a clause, while throw is a keyword. They are used with the Handle or Declare rule which states that:

If you do not want to catch an exception that is thrown in your method, then you can use the throws clause in the declaration of the method in which the exceptions takes place, to let the class where the method call occured handle the exception. So, the rule of thumb is : if you are catching the exception and not throwing it again then you dont need to use the throws clause.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic