In every control structure, if you have a limited number of options put an "else" case in that dies with an informative message. That will make this kind of error much easier to notice and track down...