Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method overriding

 
akash azal
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The overriding method must NOT throw checked exceptions that are new
or broader than those declared by the overridden method.

what does this statement means .can anyone explains with example
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose that you have the following type of exceptions

Exception1 extends Exception
Exception2 extends Exception1
Exception3 extends Exception
RuntimeException1 extends RuntimeException

and that you have a method with the following signature:



here is what you can override and what you can't override

 
Paul Stat
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example

 
akash azal
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3 runtimeexception 1 is not a child of exception1

then how it is ok

and to know this we have to know the exceptions and subexceptions by heart
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runtime exception is not a checked Exception
 
akash azal
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we have to know about exceptions and subexceptions by heart
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic