can't happen

can't happen

(programming)The traditional program comment for codeexecuted under a condition that should never be true, forexample a file size computed as negative. Often, such acondition being true indicates data corruption or a faultyalgorithm; it is almost always handled by emitting a fatalerror message and terminating or crashing, since there islittle else that can be done.

Some case variant of "can't happen" is also often the textemitted if the "impossible" error actually happens. Although"can't happen" events are genuinely infrequent in productioncode, programmers wise enough to check for them habitually areoften surprised at how frequently they are triggered duringdevelopment and how many headaches checking for them turns outto head off.

See also firewall code, professional programming.