Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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!