mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
fix a bug of traceback
This commit is contained in:
parent
b64db837f5
commit
4df6d4fdb1
@ -760,12 +760,6 @@ __NEXT_STEP:;
|
|||||||
PK_UNUSED(e);
|
PK_UNUSED(e);
|
||||||
PyObject* obj = POPX();
|
PyObject* obj = POPX();
|
||||||
Exception& _e = CAST(Exception&, obj);
|
Exception& _e = CAST(Exception&, obj);
|
||||||
int actual_ip = frame->_ip;
|
|
||||||
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
|
|
||||||
auto current_f_name = frame->co->name.sv(); // current function name
|
|
||||||
if(frame->_callable == nullptr) current_f_name = ""; // not in a function
|
|
||||||
_e.st_push(frame->co->src->snapshot(current_line, nullptr, current_f_name));
|
|
||||||
_pop_frame();
|
_pop_frame();
|
||||||
if(callstack.empty()){
|
if(callstack.empty()){
|
||||||
#if PK_DEBUG_FULL_EXCEPTION
|
#if PK_DEBUG_FULL_EXCEPTION
|
||||||
|
18
src/vm.cpp
18
src/vm.cpp
@ -1082,13 +1082,21 @@ void VM::_error(Exception e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VM::_raise(bool re_raise){
|
void VM::_raise(bool re_raise){
|
||||||
Frame* top = top_frame().get();
|
Frame* frame = top_frame().get();
|
||||||
if(!re_raise){
|
|
||||||
Exception& e = PK_OBJ_GET(Exception, s_data.top());
|
Exception& e = PK_OBJ_GET(Exception, s_data.top());
|
||||||
e._ip_on_error = top->_ip;
|
if(!re_raise){
|
||||||
e._code_on_error = (void*)top->co;
|
e._ip_on_error = frame->_ip;
|
||||||
|
e._code_on_error = (void*)frame->co;
|
||||||
}
|
}
|
||||||
bool ok = top->jump_to_exception_handler();
|
bool ok = frame->jump_to_exception_handler();
|
||||||
|
|
||||||
|
int actual_ip = frame->_ip;
|
||||||
|
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
|
||||||
|
auto current_f_name = frame->co->name.sv(); // current function name
|
||||||
|
if(frame->_callable == nullptr) current_f_name = ""; // not in a function
|
||||||
|
e.st_push(frame->co->src->snapshot(current_line, nullptr, current_f_name));
|
||||||
|
|
||||||
if(ok) throw HandledException();
|
if(ok) throw HandledException();
|
||||||
else throw UnhandledException();
|
else throw UnhandledException();
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,9 @@ try:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
s = traceback.format_exc()
|
s = traceback.format_exc()
|
||||||
|
|
||||||
assert s == r'''Traceback (most recent call last):
|
ok = s == '''Traceback (most recent call last):
|
||||||
|
File "80_traceback.py", line 5
|
||||||
|
b = a[6]
|
||||||
KeyError: 6'''
|
KeyError: 6'''
|
||||||
|
|
||||||
|
assert ok, s
|
Loading…
x
Reference in New Issue
Block a user