• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

overridin and exceptions

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
 
Don't MAKE me come back there with this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic