Key Points

  • Production code should handle errors in a more sophisticated way than "garbage in, garbage out."

  • Defensive-programming techniques make errors easier to find, easier to fix, and less damaging to production code.

  • Assertions can help detect errors early, especially in large systems, high-reliability systems, and fast-changing code bases.

  • The decision about how to handle bad inputs is a key error-handling decision and a key high-level design decision.

  • Exceptions provide a means of handling errors that operates in a different dimension from the normal flow of the code. They are a valuable addition to the programmer's intellectual toolbox when used with care, and they should be weighed against other error-processing techniques.

  • Constraints that ...

Get Code Complete, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.