diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basics/generator-exc.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/basics/generator-exc.py b/tests/basics/generator-exc.py index 601fa2c00..09aca5d9a 100644 --- a/tests/basics/generator-exc.py +++ b/tests/basics/generator-exc.py @@ -29,3 +29,25 @@ try: print(next(g)) except StopIteration: print("StopIteration") + + +# Test throwing exception into generator +def gen3(): + yield 1 + try: + yield 2 + except ValueError: + print("ValueError received") + yield 3 + yield 4 + yield 5 + +g = gen3() +print(next(g)) +print(next(g)) +print("out of throw:", g.throw(ValueError)) +print(next(g)) +try: + print("out of throw2:", g.throw(ValueError)) +except ValueError: + print("Boomerang ValueError caught") |
