Merge pull request #379 from pfalcon/reraise
vm: Implement raise statement w/o args (reraising last exception).
This commit is contained in:
commit
688e220d26
10
py/vm.c
10
py/vm.c
@ -605,8 +605,14 @@ unwind_return:
|
|||||||
|
|
||||||
case MP_BC_RAISE_VARARGS:
|
case MP_BC_RAISE_VARARGS:
|
||||||
unum = *ip++;
|
unum = *ip++;
|
||||||
assert(unum == 1);
|
assert(unum <= 1);
|
||||||
obj1 = POP();
|
if (unum == 0) {
|
||||||
|
// This assumes that nlr.ret_val holds last raised
|
||||||
|
// exception and is not overwritten since then.
|
||||||
|
obj1 = nlr.ret_val;
|
||||||
|
} else {
|
||||||
|
obj1 = POP();
|
||||||
|
}
|
||||||
nlr_jump(rt_make_raise_obj(obj1));
|
nlr_jump(rt_make_raise_obj(obj1));
|
||||||
|
|
||||||
case MP_BC_YIELD_VALUE:
|
case MP_BC_YIELD_VALUE:
|
||||||
|
12
tests/basics/try-reraise.py
Normal file
12
tests/basics/try-reraise.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Re-reraising last exception with raise w/o args
|
||||||
|
|
||||||
|
def f():
|
||||||
|
try:
|
||||||
|
raise ValueError("val", 3)
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
|
||||||
|
try:
|
||||||
|
f()
|
||||||
|
except ValueError as e:
|
||||||
|
print(repr(e))
|
Loading…
Reference in New Issue
Block a user