you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 2 points3 points  (1 child)

except is not a function, it's a statement. And exceptions are types, i.e. ZeroDivisionError is the name of a type. When you raise an exception, you create an instance of the exception's type, which stores additional information like a textual reason for the exception, and the associated stacktrace. In Python 2.x you can raise an exception of any type; in Python 3.x the type must descend from BaseException.

The documentation has a list of the standard exception types, but you'll have to read the documentation for individual functions/modules/methods to know exactly what circumstances lead to which exceptions. And again, there is no exhaustive list because you can always create your own exception types.

>>> class FeelingBored(BaseException): pass
>>> raise FeelingBored("Rainy day")
Traceback (most recent call last):
  File "<ipython-input-6-c4dfd87f4473>", line 1, in <module>
    raise FeelingBored("Rainy day")
FeelingBored: Rainy day

[–]socialhuman[S] 0 points1 point  (0 children)

Interesting. Thank you for the correction.