Should you always write code for else cases that "can never happen"?
- by johnswamps
Take some code like
if (person.IsMale()) {
doGuyStuff();
} else {
doGirlOtherStuff();
}
(Yes, I realize this is bad OO code, it's an example)
Should this be written so that to explicitly check if person.isFemale(), and then add a new else that throws an exception? Or maybe you're checking values in an enum, or something like that. You think that no one will add new elements to the enum, but who knows? "Can never happen" sounds like famous last words.