Things rarely go quite as expected, particularly in the realm of programming. An exception is what happens when Python encounters an error that would make it impossible or dangerous to continue executing the code. As you have already seen, dealing with errors is an integral part of the discipline of programming. In this chapter, you will be learning how to handle exceptions as and when they happen using try... except statements. I will introduce you to the different exception objects and the way they are organized and created and show you how to access the properties of the raised exception and then log the output. You will discover how to make proper use of tracebacks and how to create your own exception classes to cover the specific needs of your programs. Later in this chapter, you’ll find out how to handle more complex errors and grok the art of exception chaining. Finally, I’ll deal with cleaning up after the error, so the program can continue to run smoothly.


Fractional Probability File Object Class Hierarchy Exception Handling Recent Call 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Copyright information

© Tim Hall and J-P Stacey 2009

Personalised recommendations