Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
91e556af
Commit
91e556af
authored
May 02, 2014
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
objexcept: Support tracebacks for user Exception subclasses.
parent
0a7e01ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
24 deletions
+26
-24
py/objexcept.c
py/objexcept.c
+26
-24
No files found.
py/objexcept.c
View file @
91e556af
...
...
@@ -8,6 +8,7 @@
#include "qstr.h"
#include "obj.h"
#include "objtuple.h"
#include "objtype.h"
#include "runtime.h"
#include "runtime0.h"
...
...
@@ -271,38 +272,39 @@ bool mp_obj_exception_match(mp_obj_t exc, const mp_obj_type_t *exc_type) {
return
mp_binary_op
(
MP_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)
if
(
mp_obj_get_type
(
self_in
)
->
make_new
==
mp_obj_exception_make_new
)
{
mp_obj_exception_t
*
self
=
self_in
;
// just set the traceback to the null object
// we don't want to call any memory management functions here
self
->
traceback
=
MP_OBJ_NULL
;
// traceback handling functions
#define GET_NATIVE_EXCEPTION(self, self_in) \
/* make sure self_in is an exception instance */
\
assert(mp_obj_is_exception_instance(self_in)); \
mp_obj_exception_t *self; \
if (mp_obj_is_native_exception_instance(self_in)) { \
self = self_in; \
} else { \
self = ((mp_obj_instance_t*)self_in)->subobj[0]; \
}
void
mp_obj_exception_clear_traceback
(
mp_obj_t
self_in
)
{
GET_NATIVE_EXCEPTION
(
self
,
self_in
);
// just set the traceback to the null object
// we don't want to call any memory management functions here
self
->
traceback
=
MP_OBJ_NULL
;
}
void
mp_obj_exception_add_traceback
(
mp_obj_t
self_in
,
qstr
file
,
machine_uint_t
line
,
qstr
block
)
{
// make sure self_in is an exception instance
// TODO add traceback information to user-defined exceptions (need proper builtin subclassing for that)
if
(
mp_obj_get_type
(
self_in
)
->
make_new
==
mp_obj_exception_make_new
&&
self_in
!=
&
mp_emergency_exception_obj
)
{
mp_obj_exception_t
*
self
=
self_in
;
// for traceback, we are just using the list object for convenience, it's not really a list of Python objects
if
(
self
->
traceback
==
MP_OBJ_NULL
)
{
self
->
traceback
=
mp_obj_new_list
(
0
,
NULL
);
}
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
file
);
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
line
);
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
block
);
GET_NATIVE_EXCEPTION
(
self
,
self_in
);
// for traceback, we are just using the list object for convenience, it's not really a list of Python objects
if
(
self
->
traceback
==
MP_OBJ_NULL
)
{
self
->
traceback
=
mp_obj_new_list
(
0
,
NULL
);
}
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
file
);
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
line
);
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
block
);
}
void
mp_obj_exception_get_traceback
(
mp_obj_t
self_in
,
machine_uint_t
*
n
,
machine_uint_t
**
values
)
{
// make sure self_in is an exception instance
assert
(
mp_obj_get_type
(
self_in
)
->
make_new
==
mp_obj_exception_make_new
);
mp_obj_exception_t
*
self
=
self_in
;
GET_NATIVE_EXCEPTION
(
self
,
self_in
);
if
(
self
->
traceback
==
MP_OBJ_NULL
)
{
*
n
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment