Skip to content

Commit c403076

Browse files
committed
vm: Implement raise statement w/o args (reraising last exception).
1 parent 38f0c60 commit c403076

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

py/vm.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,14 @@ mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **i
604604

605605
case MP_BC_RAISE_VARARGS:
606606
unum = *ip++;
607-
assert(unum == 1);
608-
obj1 = POP();
607+
assert(unum <= 1);
608+
if (unum == 0) {
609+
// This assumes that nlr.ret_val holds last raised
610+
// exception and is not overwritten since then.
611+
obj1 = nlr.ret_val;
612+
} else {
613+
obj1 = POP();
614+
}
609615
nlr_jump(rt_make_raise_obj(obj1));
610616

611617
case MP_BC_YIELD_VALUE:

tests/basics/try-reraise.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Re-reraising last exception with raise w/o args
2+
3+
def f():
4+
try:
5+
raise ValueError("val", 3)
6+
except:
7+
raise
8+
9+
try:
10+
f()
11+
except ValueError as e:
12+
print(repr(e))

0 commit comments

Comments
 (0)