blueloveTH 1 gadu atpakaļ
vecāks
revīzija
7029ea2ee9
2 mainītis faili ar 4 papildinājumiem un 2 dzēšanām
  1. 3 2
      include/pocketpy/pocketpy.h
  2. 1 0
      src/public/py_exception.c

+ 3 - 2
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 <T> 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);

+ 1 - 0
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;
 }