Next / Previous / Contents / TCC Help System / NM Tech homepage

25.1. Definitions of exception terms

Some definitions:

If you type a statement in conversational mode that causes an exception, you will see a short traceback like this:

>>> x = 59 / 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero

The above example showed that the offending statement was read from the standard input stream (<stdin>).

When looking at a traceback, always look at the last line first. It tells you the general type of exception (in the example, a ZeroDivisionError), followed by additional details (“integer division or modulo by zero”).

If an exception occurs inside one or more function calls, the traceback will give a complete list of the functions involved, from outermost to innermost. Again, the last line shows the exception type and details.

>>> def f(): g()
... 
>>> def g(): h()
... 
>>> def h(): return 1/0
... 
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in f
  File "<stdin>", line 1, in g
  File "<stdin>", line 1, in h
ZeroDivisionError: integer division or modulo by zero