# exceptions/first.example.py # This is not a valid Python module - Don't run it. # a few examples of exceptions >>> gen = (n for n in range(2)) >>> next(gen) 0 >>> next(gen) 1 >>> next(gen) Traceback (most recent call last): File "", line 1, in StopIteration >>> print(undefined_name) Traceback (most recent call last): File "", line 1, in NameError: name 'undefined_name' is not defined >>> mylist = [1, 2, 3] >>> mylist[5] Traceback (most recent call last): File "", line 1, in IndexError: list index out of range >>> mydict = {'a': 'A', 'b': 'B'} >>> mydict['c'] Traceback (most recent call last): File "", line 1, in KeyError: 'c' >>> 1 / 0 Traceback (most recent call last): File "", line 1, in ZeroDivisionError: division by zero