Chapter 11. Exception Handling: What to Do When Things Go Wrong

image with no caption

Things go wrong, all the time—no matter how good your code is.

You’ve successfully executed all of the examples in this book, and you’re likely confident all of the code presented thus far works. But does this mean the code is robust? Probably not. Writing code based on the assumption that nothing bad ever happens is (at best) naive. At worst, it’s dangerous, as unforeseen things do (and will) happen. It’s much better if you’re wary while coding, as opposed to trusting. Care is needed to ensure your code does what you want it to, as well as reacts properly when things go south. In this chapter, you’ll not only see what can go wrong, but also learn what to do when (and, oftentimes, before) things do.

Get Head First Python, 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.