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.
KeywordsFractional Probability File Object Class Hierarchy Exception Handling Recent Call
Unable to display preview. Download preview PDF.