Chapter 7
Sidestepping Errors
IN THIS CHAPTER
Understanding exceptions
Handling errors gracefully
Keeping your app from crashing
Using try … except … else … finally
Raising your own exceptions
We all want our programs to run perfectly all the time. But sometimes there are situations out there in the real world that won't let that happen. This is no fault of yours or your program’s. It’s usually something the person using the program did wrong. Error handling is all about trying to anticipate what those problems may be, and then “catching” the error and informing the user of the problem so they can fix it.
It’s important to keep in mind the techniques here aren’t for fixing bugs in your code. Those kinds of errors you have to fix 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 ...
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