diff --git a/src/interpreter/ceval.c b/src/interpreter/ceval.c index 78ef3ece..b1f23996 100644 --- a/src/interpreter/ceval.c +++ b/src/interpreter/ceval.c @@ -1143,9 +1143,7 @@ __NEXT_STEP: } case OP_EXCEPTION_MATCH: { bool ok = false; - if(TOP()->type == tp_type) { - ok = py_isinstance(&self->unhandled_exc, py_totype(TOP())); - } else if(TOP()->type == tp_tuple) { + 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++) { @@ -1155,8 +1153,10 @@ __NEXT_STEP: break; } } - } else - goto __ERROR; + } else { + if(!py_checktype(TOP(), tp_type)) goto __ERROR; + ok = py_isinstance(&self->unhandled_exc, py_totype(TOP())); + } py_newbool(TOP(), ok); DISPATCH(); } diff --git a/tests/280_exception.py b/tests/280_exception.py index 85828d6d..104fa4ac 100644 --- a/tests/280_exception.py +++ b/tests/280_exception.py @@ -201,6 +201,11 @@ for i in range(6): a.append(i) assert a == [0, 1, 3, 4, 5] +try: + result = 10 / 0 +except (ZeroDivisionError, TypeError) as e: + assert type(e) == ZeroDivisionError + """ # finally, only def finally_only():