Defensive programming is writing each function so that it detects the situations it was not designed for, instead of computing garbage from them: it checks what it receives from outside the program and returns an error, and it asserts what its callers must guarantee.
Computer Science · Glosarium