diff --git a/include/pocketpy/pocketpy.h b/include/pocketpy/pocketpy.h index 186259a1..a397cade 100644 --- a/include/pocketpy/pocketpy.h +++ b/include/pocketpy/pocketpy.h @@ -443,8 +443,9 @@ PK_EXPORT char* py_formatexc(); /// Check if an exception is raised. PK_EXPORT bool py_checkexc(bool ignore_handled); /// Check if the exception is an instance of the given type. -/// If match, the exception will be set as handled. -PK_EXPORT bool py_matchexc(py_Type type); +/// This function is roughly equivalent to python's `except as e:` block. +/// If match, the exception will be stored in `py_retval()` as handled. +PK_EXPORT bool py_matchexc(py_Type type) PY_RETURN; /// Clear the current exception. /// @param p0 the unwinding point. Use `NULL` if not needed. PK_EXPORT void py_clearexc(py_StackRef p0); diff --git a/src/public/py_exception.c b/src/public/py_exception.c index 0d04cc13..d298f61a 100644 --- a/src/public/py_exception.c +++ b/src/public/py_exception.c @@ -142,6 +142,7 @@ bool py_matchexc(py_Type type) { if(ok) { // if match, then the exception is handled vm->is_curr_exc_handled = true; + vm->last_retval = vm->curr_exception; } return ok; }