summaryrefslogtreecommitdiff
path: root/tests/micropython/native_gen.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/micropython/native_gen.py')
-rw-r--r--tests/micropython/native_gen.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/micropython/native_gen.py b/tests/micropython/native_gen.py
index fb42f9e25..62c324634 100644
--- a/tests/micropython/native_gen.py
+++ b/tests/micropython/native_gen.py
@@ -23,3 +23,34 @@ def gen2(x):
print(list(gen2(3)))
+
+
+# catching an exception from .throw()
+@micropython.native
+def gen3():
+ try:
+ yield 1
+ yield 2
+ except Exception as er:
+ print("caught", repr(er))
+ yield 3
+
+
+g = gen3()
+print(next(g))
+print(g.throw(ValueError(42)))
+
+
+# responding to .close()
+@micropython.native
+def gen4():
+ try:
+ yield 1
+ except:
+ print("raising GeneratorExit")
+ raise GeneratorExit
+
+
+g = gen4()
+print(next(g))
+print(g.close())