The purpose of NotImplementedError is defined in the Ruby docs: NotImplementedError is raised when a feature is not implemented on the current platform. For example, methods depending on the fsync or fork system calls may raise this exception if the underlying operating system or Ruby runtime does not support them. So whenever I see code like this:
1 2 3 4 5 6 7 8 9 |
class Vehicle def manufacture(n) n.times { create } end def create raise NotImplementedError, "subclass did not define #create" end end |
I cringe. Raising NotImplementedError simply to signal that a subclass didn’t abide by the contract of its superclass is an abuse of the error. The error is intended to be raised when a method cannot be implemented due to a limitation of the underlying…
3 Comments