diff --git a/py/objexcept.c b/py/objexcept.c index df91c32b1c..d43cf979e6 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -553,7 +553,14 @@ bool mp_obj_is_exception_type(mp_obj_t self_in) { // return true if the given object is an instance of an exception type bool mp_obj_is_exception_instance(mp_obj_t self_in) { - return mp_obj_is_exception_type(MP_OBJ_FROM_PTR(mp_obj_get_type(self_in))); + if (mp_obj_is_native_exception_instance(self_in)) { + return true; + } + if (!mp_obj_is_exception_type(MP_OBJ_FROM_PTR(mp_obj_get_type(self_in)))) { + return false; + } + mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); + return self->subobj[0] != MP_OBJ_FROM_PTR((void *)&mp_native_base_init_wrapper_obj); } // Return true if exception (type or instance) is a subclass of given diff --git a/py/runtime.c b/py/runtime.c index 3fc35c8c2d..d35cf4025f 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1508,7 +1508,7 @@ mp_obj_t mp_make_raise_obj(mp_obj_t o) { } if (mp_obj_is_exception_instance(o)) { - // o is an instance of an exception, so use it as the exception + // o is a fully-constructed instance of an exception, so use it as the exception return o; } else { // o cannot be used as an exception, so return a type error (which will be raised by the caller)