Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exceptions and Overriding

 
Naina Si
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Overriding methods can't be declared to throw checked exceptions other than those that were declared by the method in the super class,

How does that work for user defined exceptions?
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand how the fact that it's a user-defined exception throws a wrench into the works. It's exactly the same. If want to override a method, you can't declare that your overridden version throws any exception types that are not assignable to one of the exception types declared to be thrown by the original method's definition. If you want to extend one of the exception types thrown by the original method (make a specific subclass of IOException for example), you can do that and throw one of those types.
 
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!