diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-26 18:46:06 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-26 18:46:06 +0000 |
commit | 752ba554ccb25a798e5279858ea8aac4af77cc1e (patch) | |
tree | ee058c8d8d17d069e32f5ae70ed508b9303b1d29 /py/objexcept.c | |
parent | 9e6e935df0583fa761148a659181813ca532cb56 (diff) | |
parent | 962b1cd1b120d777636ce8195d14f3d686e96619 (diff) | |
download | micropython-752ba554ccb25a798e5279858ea8aac4af77cc1e.tar.gz micropython-752ba554ccb25a798e5279858ea8aac4af77cc1e.zip |
Merge branch 'gen-close-ret-val' of github.com:pfalcon/micropython into pfalcon-gen-close-ret-val
Diffstat (limited to 'py/objexcept.c')
-rw-r--r-- | py/objexcept.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/py/objexcept.c b/py/objexcept.c index 79b85b28b7..c75e3d3a57 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -8,6 +8,8 @@ #include "qstr.h" #include "obj.h" #include "objtuple.h" +#include "runtime.h" +#include "runtime0.h" // This is unified class for C-level and Python-level exceptions // Python-level exceptions have empty ->msg and all arguments are in @@ -172,6 +174,11 @@ mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type) { return mp_obj_new_exception_msg_varg(exc_type, NULL); } +mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, uint n_args, const mp_obj_t *args) { + assert(exc_type->make_new == mp_obj_exception_make_new); + return exc_type->make_new((mp_obj_t)exc_type, n_args, 0, args); +} + mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg) { return mp_obj_new_exception_msg_varg(exc_type, msg); } @@ -218,6 +225,13 @@ bool mp_obj_is_exception_instance(mp_obj_t self_in) { return mp_obj_is_exception_type(mp_obj_get_type(self_in)); } +// return true if exception (type or instance) is a subclass of given +// exception type. +bool mp_obj_exception_match(mp_obj_t exc, const mp_obj_type_t *exc_type) { + // TODO: move implementation from RT_BINARY_OP_EXCEPTION_MATCH here. + return rt_binary_op(RT_BINARY_OP_EXCEPTION_MATCH, exc, (mp_obj_t)exc_type) == mp_const_true; +} + void mp_obj_exception_clear_traceback(mp_obj_t self_in) { // make sure self_in is an exception instance // TODO add traceback information to user-defined exceptions (need proper builtin subclassing for that) |