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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access