O'Reilly logo

Python: Visual QuickStart Guide, Second Edition by Toby Donaldson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. Exception Handling

Exceptions are a solution to a difficult problem: How can programs deal with unexpected errors? For instance, what happens if a file disappears in the middle of being read because some other program on your computer has deleted it? Or what if the Web site your program is downloading pages from suddenly crashes?

In these and many other situations, what Python does is raise an exception. An exception is a special kind of error object that you can catch and then examine in order to determine how to handle the error.

Exceptions can change the flow of control of your program. Depending on when it occurs, an exception can cause the flow of control to jump out of the middle of a function or loop into another block of code ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required