Affiliate disclosure

Book titles on this page link to Amazon. As an Amazon Associate, DataField.Dev earns from qualifying purchases — at no additional cost to you.

Further Reading: Error Handling

Python Exception System

  • Python Documentation: "Errors and Exceptions" Tutorial. (Tier 1) The official Python tutorial chapter on exceptions. Clear, well-written, and authoritative. Covers everything in this chapter and more, including exception chaining (raise ... from ...) and the full exception hierarchy. Available at docs.python.org/3/tutorial/errors.html.

  • Python Documentation: "Built-in Exceptions." (Tier 1) The complete list of Python's built-in exception types with their inheritance hierarchy. Essential reference when deciding which exception type to raise or catch. Available at docs.python.org/3/library/exceptions.html.

  • Hettinger, R. "Transforming Code into Beautiful, Idiomatic Python" (PyCon US 2013 talk). (Tier 1) Raymond Hettinger, a Python core developer, walks through dozens of before-and-after rewrites that turn clunky code into idiomatic Python. Relevant here: his with ignored(OSError): pattern for deliberately ignoring an exception, which became contextlib.suppress in the standard library (see Exercise G.4). Entertaining and immediately actionable. Available on YouTube.

EAFP and Pythonic Style

  • Peters, T. "The Zen of Python" (import this). (Tier 1) The guiding philosophy of Python. Several aphorisms relate directly to error handling: "Errors should never pass silently. Unless explicitly silenced." and "In the face of ambiguity, refuse the temptation to guess." Run import this in a Python REPL to read all 19 aphorisms.

  • Python Glossary: "EAFP" and "LBYL." (Tier 1) Python's official glossary entries for both concepts. Brief but authoritative. Available at docs.python.org/3/glossary.html.

Software Reliability and Defensive Programming

  • Leveson, N. & Turner, C. (1993). "An Investigation of the Therac-25 Accidents." IEEE Computer, 26(7), 18-41. (Tier 1) The definitive account of the Therac-25 radiation therapy accidents. This paper is widely used in software engineering courses to illustrate the consequences of inadequate error handling and testing. Technical but readable.

  • SEC. (2013). "In the Matter of Knight Capital Americas LLC." Exchange Act Release No. 70694 (October 16, 2013). (Tier 1) The SEC's official order on the Knight Capital trading incident, the source for most of the facts in Case Study 1. Publicly available at sec.gov/litigation/admin/2013/34-70694.pdf, and it lays out a detailed timeline of the failure. Reading a regulatory document about a software bug is a unique and sobering experience.

  • McConnell, S. (2004). Code Complete, 2nd Edition. Microsoft Press. (Tier 1) Chapter 8 ("Defensive Programming") and Chapter 22 ("Developer Testing") are directly relevant to this chapter's topics. McConnell's treatment of error handling is practical and language-agnostic. A classic software engineering reference.

Exception Handling Best Practices

  • Slatkin, B. (2019). Effective Python, 2nd Edition. Addison-Wesley. (Tier 1) Three items cover exception handling patterns: Item 20, "Prefer Raising Exceptions to Returning None"; Item 65, "Take Advantage of Each Block in try/except/else/finally"; and Item 66, "Consider contextlib and with Statements for Reusable try/finally Behavior." Concise, actionable advice. (Item 20 is a useful counterpoint to Exercise B.1, where safe_divide returns None.) The newer third edition renumbers the items, so look them up by title.

  • Ramalho, L. (2022). Fluent Python, 2nd Edition. O'Reilly. (Tier 2) Chapter 18 ("with, match, and else Blocks") covers context managers and the with statement in depth, explaining how they automate the try/finally pattern for resource management. More advanced than this chapter but valuable context for understanding why with exists.

For the Curious

  • Nygard, M. T. (2018). Release It!, 2nd Edition. Pragmatic Bookshelf. (Tier 2) A book about building software that survives production. The "Stability Patterns" chapters cover circuit breakers, bulkheads, and timeout patterns — industrial-strength versions of the error handling concepts in this chapter. The circuit breaker in Case Study 1 is a simplified cousin of Nygard's pattern.

  • Allspaw, J. (2012). "Fault Injection in Production: Making the case for resilience testing." ACM Queue, 10(8). (Tier 2) Describes how Etsy runs "GameDay" exercises: deliberately breaking parts of its live systems, on a schedule and with everyone watching, to check that the failure handling actually works. (Netflix's Chaos Monkey, which randomly shuts down production servers, is a better-known automated version of the same idea.) A fascinating approach that takes "test your error handling" to the extreme.