We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3d739eb commit 6fc6f10Copy full SHA for 6fc6f10
tests/micropython/heapalloc_exc_raise.py
@@ -0,0 +1,23 @@
1
+# Test that we can raise and catch (preallocated) exception
2
+# without memory allocation.
3
+import micropython
4
+
5
+e = ValueError("error")
6
7
+def func():
8
+ try:
9
+ # This works as is because traceback is not allocated
10
+ # if not possible (heap is locked, no memory). If heap
11
+ # is not locked, this would allocate a traceback entry.
12
+ # To avoid that, traceback should be warmed up (by raising
13
+ # it once after creation) and then cleared before each
14
+ # raise with:
15
+ # e.__traceback__ = None
16
+ raise e
17
+ except Exception as e2:
18
+ print(e2)
19
20
+micropython.heap_lock()
21
+func()
22
+print("ok")
23
+micropython.heap_unlock()
tests/micropython/heapalloc_exc_raise.py.exp
@@ -0,0 +1,2 @@
+error
+ok
0 commit comments