Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -78,6 +78,12 @@ typedef enum { ...@@ -78,6 +78,12 @@ typedef enum {
#define TOP() (*sp) #define TOP() (*sp)
#define SET_TOP(val) *sp = (val) #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 { \ #define PUSH_EXC_BLOCK(with_or_finally) do { \
DECODE_ULABEL; /* except labels are always forward */ \ DECODE_ULABEL; /* except labels are always forward */ \
++exc_sp; \ ++exc_sp; \
...@@ -89,7 +95,8 @@ typedef enum { ...@@ -89,7 +95,8 @@ typedef enum {
#define POP_EXC_BLOCK() \ #define POP_EXC_BLOCK() \
currently_in_except_block = MP_TAGPTR_TAG0(exc_sp->val_sp); /* restore previous state */ \ 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) // 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 // sp points to bottom of stack which grows up
......
...@@ -14,9 +14,8 @@ except: ...@@ -14,9 +14,8 @@ except:
print(sys.exc_info()[0:2]) print(sys.exc_info()[0:2])
f() f()
# MicroPython currently doesn't reset sys.exc_info() value # Outside except block, sys.exc_info() should be back to None's
# on exit from "except" block. f()
#f()
# Recursive except blocks are not handled either - just don't # Recursive except blocks are not handled - just don't
# use exc_info() at all! # use exc_info() at all, use explicit variables in "except".
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment