mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-23 13:00:17 +00:00
...
This commit is contained in:
parent
c6ec028730
commit
5ec1622887
@ -1551,14 +1551,14 @@ void add_module_traceback(VM* vm){
|
||||
PyObject* mod = vm->new_module("traceback");
|
||||
vm->bind_func<0>(mod, "print_exc", [](VM* vm, ArgsView args) {
|
||||
if(vm->_last_exception==nullptr) vm->ValueError("no exception");
|
||||
Exception& e = CAST(Exception&, vm->_last_exception);
|
||||
Exception& e = _CAST(Exception&, vm->_last_exception);
|
||||
vm->stdout_write(e.summary());
|
||||
return vm->None;
|
||||
});
|
||||
|
||||
vm->bind_func<0>(mod, "format_exc", [](VM* vm, ArgsView args) {
|
||||
if(vm->_last_exception==nullptr) vm->ValueError("no exception");
|
||||
Exception& e = CAST(Exception&, vm->_last_exception);
|
||||
Exception& e = _CAST(Exception&, vm->_last_exception);
|
||||
return VAR(e.summary());
|
||||
});
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ assert True
|
||||
def f():
|
||||
try:
|
||||
raise KeyError('foo')
|
||||
except A: # will fail to catch
|
||||
except IndexError: # will fail to catch
|
||||
exit(1)
|
||||
except:
|
||||
pass
|
||||
@ -52,9 +52,9 @@ def f1():
|
||||
try:
|
||||
a = {1: 2, 3: 4}
|
||||
x = a[0]
|
||||
except A:
|
||||
except RuntimeError:
|
||||
exit(1)
|
||||
except B:
|
||||
except IndexError:
|
||||
exit(1)
|
||||
exit(1)
|
||||
|
||||
@ -94,8 +94,24 @@ try:
|
||||
except IndexError as e:
|
||||
exit(1)
|
||||
except Exception as e:
|
||||
assert type(e) is KeyError
|
||||
assert str(e) == '2'
|
||||
assert repr(e).startswith('KeyError(')
|
||||
except:
|
||||
exit(1)
|
||||
|
||||
|
||||
class MyException(Exception):
|
||||
pass
|
||||
|
||||
class MyException2(MyException):
|
||||
pass
|
||||
|
||||
try:
|
||||
raise MyException2
|
||||
except MyException as e:
|
||||
ok = True
|
||||
except Exception:
|
||||
exit(1)
|
||||
|
||||
assert ok
|
@ -153,6 +153,7 @@ try:
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
class ArithmeticError(Exception): pass
|
||||
|
||||
class BadCompare:
|
||||
def __eq__(self, other):
|
||||
|
Loading…
x
Reference in New Issue
Block a user