Search code examples
pythonexceptionpython-3.xsystraceback

sys.exc_info or sys.last_*?


Should I prefer sys.exc_info() over sys.last_value and friends (sys.last_type, sys.last_traceback)?


Solution

  • Looking at the documentation of sys.last_value and friends:

    Their intended use is to allow an interactive user to import a debugger module and engage in post-mortem debugging without having to re-execute the command that caused the error.

    So, if you are in an interpreter doing debugging I suggest using sys.last_value, but in a script I suggest you to use sys.exc_info().