Win a copy of Spring in Action (5th edition) this week in the Spring 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

confused  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
my question is
overridden method must not throw any exception which is not
thrown by overridden method
is it true..
i feel overriden method should not throw any checked exception which is not thrown by overridden method
i am right
thanks in advance
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by kavita s. kumar:
Hi
my question is
overridden method must not throw any exception which is not
thrown by overridden method
is it true..
i feel overriden method should not throw any checked exception which is not thrown by overridden method
i am right
thanks in advance



Kavitha
If you override a method
The overriding method must throw nuthing/same-exceptions/subclass of the exceptions thrown by the original method
HIH
Ragu
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kavita,
I think you are right:

class A {
void m() {
System.out.println("A");
}
}
public class E extends A {
void m() throws ArrayIndexOutOfBoundsException {
System.out.println("B");
}
}
The class E compiles without problem.
So, the overriding method can throw any "unchecked" exceptions. Perhaps this is also one reason for which the some exceptions are "checked", becouse the compiler "checks" them.
..Cristian
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!