The premier defensive coding technique is the use of the assert-type statement. asserts should be use to check, at runtime, all assumptions used to generate the code. asserts check a condition and then exit if the conditions are not met.
Exception handling is a mechanism for dealing with known conditions that can be recovered from. The idea of the throw-catch metaphor is popular but not the only metaphor.
For large systems, the metaphor of a firewall is used to talk about damage containment. Concepts like information hiding and loose coupling help erect a firewall. The idea is to set up a safe area where all data is known to be correct. This allows private routines and data to be freely used without worrying about whether a particular data check has been made.
Table 15: Quality Checks in Routines