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 ...
Get Python All-in-One For Dummies 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.