Chapter 7
Sidestepping Errors
IN THIS CHAPTER
Discovering exceptions
Finding out how to handle errors gracefully
Making sure your app doesn't crash
Checking out try … except…else … finally
Learning to raise your own exceptions
We all want our programs to run perfectly all the time. But sometimes, situations in the real world stop a program from running. The problem isn't with you or your program. Usually, the person using the program did something wrong. Error handling is all about anticipating these problems, catching the error, and then informing users of the problem so that they can fix it.
The techniques we describe here aren't for fixing bugs in your code. You have to fix that type of error yourself. We’re talking strictly about errors in the environment in which the program is running, over which you have no control. Handling the error is simply a way of replacing the tech-speak error message that Python normally displays, which is meaningless to most people, with a message ...
Get Python All-in-One For Dummies, 3rd 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.