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

Overriden exception

ming ming
Ranch Hand

Joined: May 17, 2006
Posts: 54

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

Joined: May 17, 2006
Posts: 54
Sorry there is one more class
Jack malvin
Greenhorn

Joined: Nov 23, 2005
Posts: 15
Where is SmallFish?
Is she killed by some Exception.
Oops.. who is going to Handle the Exception thrown by test() ? (... More killing?)
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
try {
a.test();
} catch (Exception e) {
// clean up
}
ming ming
Ranch Hand

Joined: May 17, 2006
Posts: 54
smallfish juz added....

ming ming
Ranch Hand

Joined: May 17, 2006
Posts: 54
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??
S Thiyanesh
Ranch Hand

Joined: Mar 19, 2006
Posts: 142
throws comes with the method signature while throw new Exception() is a statement.
nitin pokhriyal
Ranch Hand

Joined: May 19, 2005
Posts: 263
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 ]
Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
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.


SCJP 1.4 85%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriden exception
 
Similar Threads
Conversion
Interface Object?
INTERFACE
Interface related
somebody pls explain why this code does not give an exception