This commit is contained in:
blueloveTH 2024-01-02 20:36:05 +08:00
parent 1a8877f28a
commit 5d8267977c
2 changed files with 7 additions and 4 deletions

View File

@ -62,7 +62,7 @@ struct Exception {
stack<ExceptionLine> stacktrace; stack<ExceptionLine> stacktrace;
Exception(StrName type): type(type), is_re(true), _ip_on_error(-1), _code_on_error(nullptr), _self(nullptr) {} Exception(StrName type): type(type), is_re(true), _ip_on_error(-1), _code_on_error(nullptr), _self(nullptr) {}
PyObject* self(){ PyObject* self() const{
PK_ASSERT(_self != nullptr); PK_ASSERT(_self != nullptr);
return _self; return _self;
} }

View File

@ -496,10 +496,13 @@ bool pkpy_py_str(pkpy_vm* vm_handle) {
bool pkpy_error(pkpy_vm* vm_handle, const char* name, pkpy_CString message) { bool pkpy_error(pkpy_vm* vm_handle, const char* name, pkpy_CString message) {
VM* vm = (VM*) vm_handle; VM* vm = (VM*) vm_handle;
PK_ASSERT_NO_ERROR() PK_ASSERT_NO_ERROR()
PyObject* e_t = vm->builtins->attr().try_get_likely_found(name); PyObject* e_t = vm->_main->attr().try_get_likely_found(name);
if(e_t == nullptr){ if(e_t == nullptr){
e_t = vm->_t(vm->tp_exception); e_t = vm->builtins->attr().try_get_likely_found(name);
std::cerr << "[warning] pkpy_error(): " << Str(name).escape() << " not found, fallback to 'Exception'" << std::endl; if(e_t == nullptr){
e_t = vm->_t(vm->tp_exception);
std::cerr << "[warning] pkpy_error(): " << Str(name).escape() << " not found, fallback to 'Exception'" << std::endl;
}
} }
vm->_c.error = vm->call(e_t, VAR(std::string_view(message.data, message.size))); vm->_c.error = vm->call(e_t, VAR(std::string_view(message.data, message.size)));
PK_OBJ_GET(Exception, vm->_c.error)._self = vm->_c.error; PK_OBJ_GET(Exception, vm->_c.error)._self = vm->_c.error;