Dup Goto 📝

TracebackModule

PT2/lang/python/old-notes 10-17 14:11:30
To Pop
12 lines, 36 words, 411 chars Tuesday 2023-10-17 14:11:30

See docs here. Note that sys.exception(), within an except, returns the current exception.

import traceback
from datetime import datetime
try:
  open("does_not_exist")
except Exception as e:
  traceback.print_exc()
  with open("exc.txt","at") as f:
    print(f"==[ {datetime.now().strftime('%c')} ]==",file=f)
    traceback.print_exc(file=f)