blob: 0f6c7c84290f6b5f4ec95f5824e91b8bf055b739 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# yield-from a user-defined generator with a throw() method
class Iter:
def __iter__(self):
return self
def __next__(self):
return 1
def throw(self, x):
print('throw', x)
return 456
def gen():
yield from Iter()
# calling close() should not call throw()
g = gen()
print(next(g))
g.close()
# can throw a non-exception object
g = gen()
print(next(g))
print(g.throw(123))
# throwing an exception class just injects that class
g = gen()
print(next(g))
print(g.throw(ZeroDivisionError))
|