Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
I didn’t really pull the prior section’s examples out of thin air. All built-in exceptions that Python itself may raise are predefined class objects. Moreover, they are organized into a shallow hierarchy with general superclass categories and specific subclass types, much like the exceptions class tree we developed earlier.
In Python 3.0, all the familiar exceptions you’ve seen (e.g.,
SyntaxError) are really just
predefined classes, available as built-in names in the module named
builtins (in Python 2.6, they
instead live in __builtin__ and are
also attributes of the standard library module exceptions). In addition, Python organizes the built-in exceptions into a hierarchy, to
support a variety of catching modes. For example: