diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-03-22 17:50:12 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-03-22 17:55:42 +0200 |
commit | 48caa09a9dd4b53656f58f622cf38341b6c099dc (patch) | |
tree | f1ee33c29869906cfb5a669d595c6850709198f3 /tests/basics/generator-exc.py | |
parent | 61fd20f168e96efe1f85246401ee4871a14ad9bd (diff) | |
download | micropython-48caa09a9dd4b53656f58f622cf38341b6c099dc.tar.gz micropython-48caa09a9dd4b53656f58f622cf38341b6c099dc.zip |
objgenerator: Implement .throw() method to throw exceptions into generator.
Diffstat (limited to 'tests/basics/generator-exc.py')
-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 601fa2c00e..09aca5d9a0 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") |