Agreed, throw exception instead of return null

Published:
Reading time:
About 1 min

Blaine tells us Don’t use null or -1 in your unwritten methods, and I have to agree. He’s pointing to Tim Bray’s error in unit testing.

I have to say this is a great idea, and should be used by everyone. That is, instead of returning null or -1 for an unimplemented method, you should throw a RuntimeException (“Method has not been implemented”). Even better would be to create your own UnimplementedMethodException and throw that.

Good stuff to read for breakfast!