mirror of
https://github.com/pocketpy/pocketpy
synced 2025-12-10 20:20:18 +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");
|
PyObject* mod = vm->new_module("traceback");
|
||||||
vm->bind_func<0>(mod, "print_exc", [](VM* vm, ArgsView args) {
|
vm->bind_func<0>(mod, "print_exc", [](VM* vm, ArgsView args) {
|
||||||
if(vm->_last_exception==nullptr) vm->ValueError("no exception");
|
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());
|
vm->stdout_write(e.summary());
|
||||||
return vm->None;
|
return vm->None;
|
||||||
});
|
});
|
||||||
|
|
||||||
vm->bind_func<0>(mod, "format_exc", [](VM* vm, ArgsView args) {
|
vm->bind_func<0>(mod, "format_exc", [](VM* vm, ArgsView args) {
|
||||||
if(vm->_last_exception==nullptr) vm->ValueError("no exception");
|
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());
|
return VAR(e.summary());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,7 @@ assert True
|
|||||||
def f():
|
def f():
|
||||||
try:
|
try:
|
||||||
raise KeyError('foo')
|
raise KeyError('foo')
|
||||||
except A: # will fail to catch
|
except IndexError: # will fail to catch
|
||||||
exit(1)
|
exit(1)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@ -52,9 +52,9 @@ def f1():
|
|||||||
try:
|
try:
|
||||||
a = {1: 2, 3: 4}
|
a = {1: 2, 3: 4}
|
||||||
x = a[0]
|
x = a[0]
|
||||||
except A:
|
except RuntimeError:
|
||||||
exit(1)
|
exit(1)
|
||||||
except B:
|
except IndexError:
|
||||||
exit(1)
|
exit(1)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
@ -94,8 +94,24 @@ try:
|
|||||||
except IndexError as e:
|
except IndexError as e:
|
||||||
exit(1)
|
exit(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
assert type(e) is KeyError
|
||||||
assert str(e) == '2'
|
assert str(e) == '2'
|
||||||
assert repr(e).startswith('KeyError(')
|
assert repr(e).startswith('KeyError(')
|
||||||
except:
|
except:
|
||||||
exit(1)
|
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:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class ArithmeticError(Exception): pass
|
||||||
|
|
||||||
class BadCompare:
|
class BadCompare:
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user