mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
This commit is contained in:
parent
5d3d9b2dec
commit
7a7ded5735
@ -44,8 +44,9 @@ struct Exception {
|
|||||||
stack<Str> stacktrace;
|
stack<Str> stacktrace;
|
||||||
|
|
||||||
int _ip_on_error;
|
int _ip_on_error;
|
||||||
|
void* _code_on_error;
|
||||||
|
|
||||||
Exception(StrName type, Str msg): type(type), msg(msg), is_re(true), _ip_on_error(-1) {}
|
Exception(StrName type, Str msg): type(type), msg(msg), is_re(true), _ip_on_error(-1), _code_on_error(nullptr) {}
|
||||||
bool match_type(StrName t) const { return this->type == t;}
|
bool match_type(StrName t) const { return this->type == t;}
|
||||||
void st_push(Str&& snapshot);
|
void st_push(Str&& snapshot);
|
||||||
Str summary() const;
|
Str summary() const;
|
||||||
|
@ -352,8 +352,14 @@ public:
|
|||||||
_error(Exception(name, msg));
|
_error(Exception(name, msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _raise(){
|
void _raise(bool re_raise=false){
|
||||||
bool ok = top_frame()->jump_to_exception_handler();
|
Frame* top = top_frame().get();
|
||||||
|
if(!re_raise){
|
||||||
|
Exception& e = PK_OBJ_GET(Exception, s_data.top());
|
||||||
|
e._ip_on_error = top->_ip;
|
||||||
|
e._code_on_error = (void*)top->co;
|
||||||
|
}
|
||||||
|
bool ok = top->jump_to_exception_handler();
|
||||||
if(ok) throw HandledException();
|
if(ok) throw HandledException();
|
||||||
else throw UnhandledException();
|
else throw UnhandledException();
|
||||||
}
|
}
|
||||||
|
@ -695,7 +695,7 @@ __NEXT_STEP:;
|
|||||||
Str msg = _0 == None ? "" : CAST(Str, py_str(_0));
|
Str msg = _0 == None ? "" : CAST(Str, py_str(_0));
|
||||||
_error(StrName(byte.arg), msg);
|
_error(StrName(byte.arg), msg);
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
TARGET(RE_RAISE) _raise(); DISPATCH();
|
TARGET(RE_RAISE) _raise(true); DISPATCH();
|
||||||
TARGET(POP_EXCEPTION) _last_exception = POPX(); DISPATCH();
|
TARGET(POP_EXCEPTION) _last_exception = POPX(); DISPATCH();
|
||||||
/*****************************************/
|
/*****************************************/
|
||||||
TARGET(FORMAT_STRING) {
|
TARGET(FORMAT_STRING) {
|
||||||
@ -751,7 +751,7 @@ __NEXT_STEP:;
|
|||||||
PyObject* obj = POPX();
|
PyObject* obj = POPX();
|
||||||
Exception& _e = CAST(Exception&, obj);
|
Exception& _e = CAST(Exception&, obj);
|
||||||
int actual_ip = frame->_ip;
|
int actual_ip = frame->_ip;
|
||||||
if(_e._ip_on_error >= 0) actual_ip = _e._ip_on_error;
|
if(_e._ip_on_error >= 0 && _e._code_on_error == (void*)frame->co) actual_ip = _e._ip_on_error;
|
||||||
int current_line = frame->co->lines[actual_ip]; // current line
|
int current_line = frame->co->lines[actual_ip]; // current line
|
||||||
auto current_f_name = frame->co->name.sv(); // current function name
|
auto current_f_name = frame->co->name.sv(); // current function name
|
||||||
if(frame->_callable == nullptr) current_f_name = ""; // not in a function
|
if(frame->_callable == nullptr) current_f_name = ""; // not in a function
|
||||||
|
@ -1069,7 +1069,6 @@ PyObject* VM::bind_property(PyObject* obj, Str name, NativeFuncC fget, NativeFun
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VM::_error(Exception e){
|
void VM::_error(Exception e){
|
||||||
e._ip_on_error = top_frame()->_ip;
|
|
||||||
if(callstack.empty()){
|
if(callstack.empty()){
|
||||||
e.is_re = false;
|
e.is_re = false;
|
||||||
throw e;
|
throw e;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user