On this page
sys.exception
Prev: sys.excepthook | Up: sys | Next: sys.exit
Rel: sys.activate_stack_trampoline, sys.addaudithook, sys.audit, sys.breakpointhook
Ref: docs.python.org — sys.exception
Tags: #public #python3 #stdlib #sys
Import
import sys
from sys import exception
Signature & Overview
sys.exception()
Return the current exception.
Usage
import sys
assert sys.exception() is None
try:
raise ValueError("bad")
except ValueError:
assert isinstance(sys.exception(), ValueError)
Gotchas
- Requires Python 3.11+: Cleaner than
sys.exc_info()[1]because the exception already carries.__traceback__andtype(exc).
REPL Inspect
from sys import exception
help(exception)
Linked from
Related notes
- tuts/python3/stdlib_module/sys/excepthook Linked here; links to this page; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/exit 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/displayhook shared tags: #stdlib, #sys