mirror of
https://github.com/pocketpy/pocketpy
synced 2026-02-04 06:30:17 +00:00
Merge 1c0daadb18e09c6636184321b12749ec6600d189 into 2fa14c588463bf576bce766f6ae996e7e8e10271
This commit is contained in:
commit
a2ea9d7b16
@ -1142,10 +1142,39 @@ __NEXT_STEP:
|
|||||||
DISPATCH();
|
DISPATCH();
|
||||||
}
|
}
|
||||||
case OP_EXCEPTION_MATCH: {
|
case OP_EXCEPTION_MATCH: {
|
||||||
if(!py_checktype(TOP(), tp_type)) goto __ERROR;
|
bool ok = false;
|
||||||
bool ok = py_isinstance(&self->unhandled_exc, py_totype(TOP()));
|
bool has_invalid = false;
|
||||||
py_newbool(TOP(), ok);
|
if(TOP()->type == tp_type) {
|
||||||
DISPATCH();
|
ok = py_isinstance(&self->unhandled_exc, py_totype(TOP()));
|
||||||
|
} else if(TOP()->type == tp_tuple) {
|
||||||
|
int len = py_tuple_len(TOP());
|
||||||
|
py_ObjectRef data = py_tuple_data(TOP());
|
||||||
|
for(int i = 0; i < len; i++) {
|
||||||
|
if((data + i)->type != tp_type) {
|
||||||
|
has_invalid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!has_invalid) {
|
||||||
|
for(int i = 0; i < len; i++) {
|
||||||
|
if(py_isinstance(&self->unhandled_exc, py_totype(data + i))) {
|
||||||
|
ok = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
has_invalid = true;
|
||||||
|
}
|
||||||
|
if(has_invalid) {
|
||||||
|
py_newnil(&self->unhandled_exc);
|
||||||
|
TypeError("catching classes that do not inherit from BaseException is not allowed");
|
||||||
|
c11_vector__pop(&frame->exc_stack);
|
||||||
|
goto __ERROR;
|
||||||
|
} else {
|
||||||
|
py_newbool(TOP(), ok);
|
||||||
|
DISPATCH();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case OP_HANDLE_EXCEPTION: {
|
case OP_HANDLE_EXCEPTION: {
|
||||||
FrameExcInfo* info = Frame__top_exc_info(frame);
|
FrameExcInfo* info = Frame__top_exc_info(frame);
|
||||||
|
|||||||
@ -201,6 +201,21 @@ for i in range(6):
|
|||||||
a.append(i)
|
a.append(i)
|
||||||
assert a == [0, 1, 3, 4, 5]
|
assert a == [0, 1, 3, 4, 5]
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = 10 / 0
|
||||||
|
except (ZeroDivisionError, TypeError) as e:
|
||||||
|
assert type(e) == ZeroDivisionError
|
||||||
|
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
result = 10 / 0
|
||||||
|
except (ZeroDivisionError, 1) as e:
|
||||||
|
assert False
|
||||||
|
except (TypeError) as e:
|
||||||
|
assert False
|
||||||
|
except Exception as e:
|
||||||
|
assert type(e) == TypeError
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# finally, only
|
# finally, only
|
||||||
def finally_only():
|
def finally_only():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user