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

vm: On exiting except block, clear sys.exc_info() value.

This doesn't handle case fo enclosed except blocks, but once again,
sys.exc_info() support is a workaround for software which uses it
instead of properly catching exceptions via variable in except clause.
parent 0f553fe1
......@@ -78,6 +78,12 @@ typedef enum {
#define TOP() (*sp)
#define SET_TOP(val) *sp = (val)
#if MICROPY_PY_SYS_EXC_INFO
#define CLEAR_SYS_EXC_INFO() MP_STATE_VM(cur_exception) = MP_OBJ_NULL;
#else
#define CLEAR_SYS_EXC_INFO()
#endif
#define PUSH_EXC_BLOCK(with_or_finally) do { \
DECODE_ULABEL; /* except labels are always forward */ \
++exc_sp; \
......@@ -89,7 +95,8 @@ typedef enum {
#define POP_EXC_BLOCK() \
currently_in_except_block = MP_TAGPTR_TAG0(exc_sp->val_sp); /* restore previous state */ \
exc_sp--; /* pop back to previous exception handler */
exc_sp--; /* pop back to previous exception handler */ \
CLEAR_SYS_EXC_INFO() /* just clear sys.exc_info(), not compliant, but it shouldn't be used in 1st place */
// fastn has items in reverse order (fastn[0] is local[0], fastn[-1] is local[1], etc)
// sp points to bottom of stack which grows up
......
......@@ -14,9 +14,8 @@ except:
print(sys.exc_info()[0:2])
f()
# MicroPython currently doesn't reset sys.exc_info() value
# on exit from "except" block.
#f()
# Outside except block, sys.exc_info() should be back to None's
f()
# Recursive except blocks are not handled either - just don't
# use exc_info() at all!
# Recursive except blocks are not handled - just don't
# use exc_info() at all, use explicit variables in "except".
Supports Markdown
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