Physical pinball machines have sensors in them that detect when something outside is trying to exert too much influence the path of the ball by nudging or tilting the machine. (I say too much here because pinball has a long tradition of a a certain amount of motion being acceptable, especially when the ball gets hung up on something.) When the machine goes into the tilted state, anything that could score the player more points is disabled until the ball falls off the bottom of the table. This is usually accompanied by a "Tilt" light on the game and sometimes a warning buzzer. Think of it as the pinball equivalent of raising an exception.
Martin's metaphor is strained because ErrorCode.OK
is, presumably, a valid status
and not something that tries to force the function into doing something it shouldn't. In other words, that input isn't trying to get the function to return the error message for a missing argument.
The rest of this doesn't answer your question, but it may give you reason to read the rest of the book with a critical eye. I don't have access to the book to see if the text surrounding that example does any hand-waving, but if not, the method does things that don't live up to the title :
First is that it doesn't treat presumably-invalid input or state as an exceptional condition and complain about it. If the method's documentation says it should only be called when the object's status
is in an error state, it's clearly a logic problem in the calling code that needs to be corrected.
Second is that it returns a string that's just as valid as any of the others but effectively serves as a magic constant. A caller wanting to know if invoking the method was a mistake will have to check the contents of the return value or blithely pass it on to the human reading it to decipher (e.g., Operation result:
with no additional information).
An optional third would be that if the compiler expects full coverage of the enumerated values, using default
to catch the un-covered cases is a lot more readable than having to enumerate them individually or in a group. (The filp side is that it might be better to let the compiler complain so that adding a second, non-error status would force the programmer to explicitly declare how it should be handled.)