This commit is contained in:
blueloveTH 2024-08-16 11:27:53 +08:00
parent d14e861b2e
commit 7029ea2ee9
2 changed files with 4 additions and 2 deletions

View File

@ -443,8 +443,9 @@ PK_EXPORT char* py_formatexc();
/// Check if an exception is raised. /// Check if an exception is raised.
PK_EXPORT bool py_checkexc(bool ignore_handled); PK_EXPORT bool py_checkexc(bool ignore_handled);
/// Check if the exception is an instance of the given type. /// Check if the exception is an instance of the given type.
/// If match, the exception will be set as handled. /// This function is roughly equivalent to python's `except <T> as e:` block.
PK_EXPORT bool py_matchexc(py_Type type); /// 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. /// Clear the current exception.
/// @param p0 the unwinding point. Use `NULL` if not needed. /// @param p0 the unwinding point. Use `NULL` if not needed.
PK_EXPORT void py_clearexc(py_StackRef p0); PK_EXPORT void py_clearexc(py_StackRef p0);

View File

@ -142,6 +142,7 @@ bool py_matchexc(py_Type type) {
if(ok) { if(ok) {
// if match, then the exception is handled // if match, then the exception is handled
vm->is_curr_exc_handled = true; vm->is_curr_exc_handled = true;
vm->last_retval = vm->curr_exception;
} }
return ok; return ok;
} }