summaryrefslogtreecommitdiff
path: root/py/objexcept.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-03-26 19:17:20 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-03-26 19:29:36 +0200
commitaf1ae3039913785cc9a36d93a23e4bcca5ec83e7 (patch)
tree756221fdf410bdb99d47d5d6ef346b6e8e3ed3e5 /py/objexcept.c
parent38f0c607b0626ecee9cb2e4aefb25c3756232dab (diff)
objexcept: Add mp_obj_exception_get_value() convenience function.
This gets "value" of exceptions in the sense as it's defined for StopIteration.value (i.e. args[0] or None). TODO: This really should be inline function.
Diffstat (limited to 'py/objexcept.c')
-rw-r--r--py/objexcept.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/py/objexcept.c b/py/objexcept.c
index 0650920e7..8be3048fa 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -59,16 +59,22 @@ STATIC mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, uint n_args, uint n_
return o;
}
+// Get exception "value" - that is, first argument, or None
+mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in) {
+ mp_obj_exception_t *self = self_in;
+ if (self->args.len == 0) {
+ return mp_const_none;
+ } else {
+ return self->args.items[0];
+ }
+}
+
STATIC void exception_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
mp_obj_exception_t *self = self_in;
if (attr == MP_QSTR_args) {
dest[0] = &self->args;
} else if (self->base.type == &mp_type_StopIteration && attr == MP_QSTR_value) {
- if (self->args.len == 0) {
- dest[0] = mp_const_none;
- } else {
- dest[0] = self->args.items[0];
- }
+ dest[0] = mp_obj_exception_get_value(self);
}
}