Stack trace



examples/exceptions/stack_trace.py
import traceback

def bar():
    foo()

def foo():
    raise Exception("hi")

def main():
    try:
        bar()
    except Exception as err:
        track = traceback.format_exc()
        print(track)

    print("---------------------")
    bar()


main()

Traceback (most recent call last):
  File "stack_trace.py", line 11, in main
    bar()
  File "stack_trace.py", line 4, in bar
    foo()
  File "stack_trace.py", line 7, in foo
    raise Exception("hi")
Exception: hi

---------------------
Traceback (most recent call last):
  File "stack_trace.py", line 20, in <module>
    main()
  File "stack_trace.py", line 17, in main
    bar()
  File "stack_trace.py", line 4, in bar
    foo()
  File "stack_trace.py", line 7, in foo
    raise Exception("hi")
Exception: hi