ch07
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
# 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 "<stdin>", line 1, in <module>
|
||||
StopIteration
|
||||
>>> print(undefined_name)
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
NameError: name 'undefined_name' is not defined
|
||||
>>> mylist = [1, 2, 3]
|
||||
>>> mylist[5]
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
IndexError: list index out of range
|
||||
>>> mydict = {'a': 'A', 'b': 'B'}
|
||||
>>> mydict['c']
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
KeyError: 'c'
|
||||
>>> 1 / 0
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
ZeroDivisionError: division by zero
|
||||
Reference in New Issue
Block a user