On this page
sys.exc_info
Prev: sys.displayhook | Up: sys | Next: sys.excepthook
Rel: sys.activate_stack_trampoline, sys.addaudithook, sys.audit, sys.breakpointhook
Ref: docs.python.org — sys.exc_info
Tags: #public #python3 #stdlib #sys
Import
import sys
from sys import exc_info
Signature & Overview
sys.exc_info()
Return current exception information: (type, value, traceback).
Usage
import sys
try:
1 / 0
except ZeroDivisionError:
exc_type, exc_val, exc_tb = sys.exc_info()
assert exc_type is ZeroDivisionError and isinstance(exc_val, ZeroDivisionError)
Gotchas
- Prefer
sys.exception()in Python 3.11+:exc_info()returns(None, None, None)outside anexceptblock; don't storeexc_tbin long-lived objects or you'll keep local frame references alive.
REPL Inspect
from sys import exc_info
help(exc_info)
Linked from
Related notes
- tuts/python3/stdlib_module/sys/displayhook Linked here; links to this page; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/excepthook Linked here; links to this page; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sys/activate_stack_trampoline Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/addaudithook Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/audit Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/breakpointhook Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/call_tracing shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/deactivate_stack_trampoline shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/exception shared tags: #stdlib, #sys