A conversation about exceptions

Other person: The subclasses of this Foo parent class are supposed to define method bar(). So we should define Foo.bar() and have it raise an exception.

Me: Why?

Other person: So if subclass_instance.bar() is called, and the subclass hasn’t overridden bar(), it’ll raise an exception. That way we’ll know when the method is missing on a subclass!

Me: If we don’t define bar() in the parent class, what happens if a subclass also doesn’t define it, and code calls subclass.bar()?

Other person: It raises an exception.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.