Summary

In this chapter, we’ve learned about exceptions—both how to catch them with try statements and how to trigger them with raise statements. Exceptions are identified by string objects or class objects; built-in exceptions are predefined class objects in Python 1.5, but user-defined exceptions may be strings or classes. Either way, exceptions let us jump around programs arbitrarily, and provide a coherent way of dealing with errors and other unusual events. Along the way, we studied common exception idioms, touched on error handling in general, and saw a variety of ways to catch and match raised exceptions.

This chapter concludes our look at the core Python programming language. If you’ve gotten this far, you can consider yourself an official Python programmer; you’ve already seen just about everything there is to see in regards to the language itself. In this part of the book, we studied built-in types, statements, and exceptions, as well as tools used to build-up larger program units—functions, modules, and classes. In general, Python provides a hierarchy of tool sets:

Built-ins

Built-in types like strings, lists, and dictionaries make it easy to write simple programs fast.

Python extensions

For more demanding tasks, we can extend Python in Python, by writing our own functions, modules, and classes.

C extensions

Although we don’t cover them in this book, Python can also be extended with modules written in C or C++.

Because Python layers its tool sets, we can decide how complicated ...

Get Learning Python 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.