blob: 601fa2c00e5e447df2b2f956a4d1db420b1e7d6d (
plain)
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
31
|
# Test proper handling of exceptions within generator across yield
def gen():
try:
yield 1
raise ValueError
except ValueError:
print("Caught")
yield 2
for i in gen():
print(i)
# Test throwing exceptions out of generator
def gen2():
yield 1
raise ValueError
yield 2
yield 3
g = gen2()
print(next(g))
try:
print(next(g))
except ValueError:
print("ValueError")
try:
print(next(g))
except StopIteration:
print("StopIteration")
|