Skip to content
Snippets Groups Projects
Select Git revision
  • 1da77e425ed215b347018d49337e2fd53e5a8fd1
  • main default protected
  • phhw
  • captouch-threshold
  • t
  • dos
  • test2
  • test
  • slewtest
  • simtest
  • view-think
  • vm-pending
  • media-buf
  • scope
  • passthrough
  • wave
  • vsync
  • dos-main-patch-50543
  • json-error
  • rahix/big-flow3r
  • pippin/media_framework
  • v1.3.0
  • v1.2.0
  • v1.2.0+rc1
  • v1.1.1
  • v1.1.0
  • v1.1.0+rc1
  • v1.0.0
  • v1.0.0+rc6
  • v1.0.0+rc5
  • v1.0.0+rc4
  • v1.0.0+rc3
  • v1.0.0+rc2
  • v1.0.0+rc1
34 results

scroll_demo.py

Blame
  • Forked from flow3r / flow3r firmware
    Source project has a limited visibility.
    print_exception.py 1.05 KiB
    import _io as io # uPy does not have io module builtin
    import sys
    if hasattr(sys, 'print_exception'):
        print_exception = sys.print_exception
    else:
        import traceback
        print_exception = lambda e, f: traceback.print_exception(None, e, sys.exc_info()[2], file=f)
    
    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 "):
                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:
        1/0
    except Exception as e:
        print('caught')
        print_exc(e)
    
    # exception message with more than 1 source-code line
    def f():
        g()
    def g():
        2/0
    try:
        f()
    except Exception as e:
        print('caught')
        print_exc(e)