This week's book giveaways are in the Angular and TypeScript and Web Services forums.
We're giving away four copies each of Programming with Types and The Design of Web APIs and have the authors on-line!
See this thread and this one for details.
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
  • 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

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
 
Space pants. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!