Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

overridin and exceptions

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
regardin overidding.
class drum
{
void method2(int j)
{
}
}
public class vote extends drum
{
void method2(final int j)throws ArithmeticException
{

}
}

this code does not give compile error.
but how can a method in vote class throw an exception if the
method in drum class does not throw it also.
but if i just give throws Exception instead of ArithmeticException
it gives error as expected.
rules for ovrriding r , u cannot define the new method to throw
exceptions unless it is defined in the original method right???
so in thiscase there is no exception in method in drum class
but there is one in vote class ,
how is tht possible ??
thx
regards
Kamal
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi..
well.. the code compiles because ArithmeticException is a subclass of RuntimeException, that means that it is an unchecked exception and an overridden method has the limitation that it cannot throw any other CHECKED exceptions apart from which the original method is throwing, it doesn't say anything about the unchecked exceptions and ArithmeticException is an unchecked one.
hope this helps..

------------------
Hima
 
kamal jaisingh
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thx hima
now i get it much clearly.
can u also tell me wht r the other unchecked exceptions
just like ArithmeticExcpetion is an unchecked Exception

regards
Kamal J
 
Hima Mangal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi kamal..
well.. i think u will do better to go thru RHE for this for an exhaustive list.. at the moment, i can recall only a couple like ArrayIndexOutOfBoundsException, ClassCastException etc..
if u have any further probs in finding them, pls let me know..

------------------
Hima
reply
    Bookmark Topic Watch Topic
  • New Topic