Commit d109676e authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

py: Reraising exception possible only in except block.

parent f4417a1f
...@@ -697,6 +697,9 @@ unwind_return: ...@@ -697,6 +697,9 @@ unwind_return:
unum = *ip++; unum = *ip++;
assert(unum <= 1); assert(unum <= 1);
if (unum == 0) { if (unum == 0) {
if (!currently_in_except_block) {
nlr_jump(mp_obj_new_exception_msg(&mp_type_RuntimeError, "No active exception to reraise"));
}
// This assumes that nlr.ret_val holds last raised // This assumes that nlr.ret_val holds last raised
// exception and is not overwritten since then. // exception and is not overwritten since then.
obj1 = nlr.ret_val; obj1 = nlr.ret_val;
......
# Re-reraising last exception with raise w/o args # Reraising last exception with raise w/o args
def f(): def f():
try: try:
...@@ -10,3 +10,10 @@ try: ...@@ -10,3 +10,10 @@ try:
f() f()
except ValueError as e: except ValueError as e:
print(repr(e)) print(repr(e))
# Can reraise only in except block
try:
raise
except RuntimeError:
print("RuntimeError")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment