diff options
author | Damien George <damien.p.george@gmail.com> | 2015-02-27 00:36:39 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-02-27 00:36:39 +0000 |
commit | 4852e09c7914a4d4f2938dddbe155a2075bb2eb3 (patch) | |
tree | c1a6677c13cd5394a0c574eea31d1f33259edcd3 /tests/misc/print_exception.py | |
parent | d155fecf9e27617d23a2249dacdbbcc203bdd85e (diff) | |
download | micropython-4852e09c7914a4d4f2938dddbe155a2075bb2eb3.tar.gz micropython-4852e09c7914a4d4f2938dddbe155a2075bb2eb3.zip |
py: Fix adding of traceback so that it appends to existing info.
This makes exception traceback info self contained (ie doesn't rely on
list object, which was a bit of a hack), reduces code size, and reduces
RAM footprint of exception by eliminating the list object.
Addresses part of issue #1126.
Diffstat (limited to 'tests/misc/print_exception.py')
-rw-r--r-- | tests/misc/print_exception.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/tests/misc/print_exception.py b/tests/misc/print_exception.py index e65b8d1ac5..4e23bf1543 100644 --- a/tests/misc/print_exception.py +++ b/tests/misc/print_exception.py @@ -6,19 +6,35 @@ else: import traceback print_exception = lambda e, f: traceback.print_exception(None, e, None, file=f) -try: - XXX -except Exception as e: - print('caught') +def print_exc(e): buf = io.StringIO() print_exception(e, buf) s = buf.getvalue() for l in s.split("\n"): # uPy on pyboard prints <stdin> as file, so remove filename. if l.startswith(" File "): - print(l[:8], l[-23:]) + l = l.split('"') + print(l[0], l[2]) # uPy and CPy tracebacks differ in that CPy prints a source line for # each traceback entry. In this case, we know that offending line # has 4-space indent, so filter it out. elif not l.startswith(" "): print(l) + +# basic exception message +try: + XXX +except Exception as e: + print('caught') + print_exc(e) + +# exception message with more than 1 source-code line +def f(): + g() +def g(): + YYY +try: + f() +except Exception as e: + print('caught') + print_exc(e) |