summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--py/emitnative.c4
-rw-r--r--tests/basics/try_finally1.py13
2 files changed, 16 insertions, 1 deletions
diff --git a/py/emitnative.c b/py/emitnative.c
index 5db496a22..a5075eead 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -1892,7 +1892,9 @@ STATIC void emit_native_pop_block(emit_t *emit) {
}
STATIC void emit_native_pop_except(emit_t *emit) {
- (void)emit;
+ // Cancel any active exception so subsequent handlers don't see it
+ ASM_MOV_REG_IMM(emit->as, REG_TEMP0, (mp_uint_t)mp_const_none);
+ ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_VAL(emit), REG_TEMP0);
}
STATIC void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) {
diff --git a/tests/basics/try_finally1.py b/tests/basics/try_finally1.py
index 2416f6d18..1e821deb6 100644
--- a/tests/basics/try_finally1.py
+++ b/tests/basics/try_finally1.py
@@ -69,3 +69,16 @@ try: # top-level catch-all except to not fail script
except:
print("catch-all except")
print()
+
+# case where a try-except within a finally cancels the exception
+print("exc-finally-subexcept")
+try:
+ print("try1")
+finally:
+ try:
+ print("try2")
+ foo
+ except:
+ print("except2")
+ print("finally1")
+print()