2016-11-21 01:39:23 -05:00
|
|
|
# test that we can generate a traceback without allocating
|
|
|
|
|
|
|
|
import micropython
|
|
|
|
import sys
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-09 04:26:31 -05:00
|
|
|
try:
|
|
|
|
import uio
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
2017-06-10 13:14:16 -04:00
|
|
|
raise SystemExit
|
2016-11-21 01:39:23 -05:00
|
|
|
|
|
|
|
# preallocate exception instance with some room for a traceback
|
|
|
|
global_exc = StopIteration()
|
|
|
|
try:
|
|
|
|
raise global_exc
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2016-11-21 01:39:23 -05:00
|
|
|
def test():
|
2017-12-11 04:56:20 -05:00
|
|
|
micropython.heap_lock()
|
2016-11-21 01:39:23 -05:00
|
|
|
global global_exc
|
|
|
|
global_exc.__traceback__ = None
|
|
|
|
try:
|
|
|
|
raise global_exc
|
2016-12-14 19:11:57 -05:00
|
|
|
except StopIteration:
|
2020-03-22 22:26:08 -04:00
|
|
|
print("StopIteration")
|
2017-12-11 04:56:20 -05:00
|
|
|
micropython.heap_unlock()
|
2016-11-21 01:39:23 -05:00
|
|
|
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2016-11-21 01:39:23 -05:00
|
|
|
# call test() with heap allocation disabled
|
|
|
|
test()
|
2016-12-14 19:11:57 -05:00
|
|
|
|
|
|
|
# print the exception that was raised
|
|
|
|
buf = uio.StringIO()
|
|
|
|
sys.print_exception(global_exc, buf)
|
|
|
|
for l in buf.getvalue().split("\n"):
|
|
|
|
# uPy on pyboard prints <stdin> as file, so remove filename.
|
|
|
|
if l.startswith(" File "):
|
|
|
|
l = l.split('"')
|
|
|
|
print(l[0], l[2])
|
|
|
|
else:
|
|
|
|
print(l)
|