1# test that emergency exceptions work 2 3import micropython 4import usys 5 6try: 7 import uio 8except ImportError: 9 print("SKIP") 10 raise SystemExit 11 12# some ports need to allocate heap for the emg exc 13try: 14 micropython.alloc_emergency_exception_buf(256) 15except AttributeError: 16 pass 17 18 19def f(): 20 micropython.heap_lock() 21 try: 22 raise ValueError(1) 23 except ValueError as er: 24 exc = er 25 micropython.heap_unlock() 26 27 # print the exception 28 buf = uio.StringIO() 29 usys.print_exception(exc, buf) 30 for l in buf.getvalue().split("\n"): 31 if l.startswith(" File "): 32 print(l.split('"')[2]) 33 else: 34 print(l) 35 36 37f() 38