Grabbing frogs...

Throw It Back

Are you an Exception? I'm supposed to catch Exceptions.


No, I'm a fish.


A fish? I think I'm supposed to cook those.


Not me. I'm an exception.


Confused? Is it an Exception or a Fish? Can it be both? Not in Java, unless it's a FishException which inherits from Exception and implements the Fish interface.

The moral of the story is that you should favor composition over inheritance. No, wait, it's that you should either handle Exceptions or Throw them - not both. No, wait, it's that you shouldn't talk to fish.

Published Friday, 10 June 2016

Vote for us on!
Our Current Rank is: 0