ID EN
Built-in Exceptions

__context__

Python 3.11

When raising a new exception while another exception is already being handled, the new exception’s __context__ attribute is automatically set to the handled exception. An exception may be handled when an except or finally clause, or a with statement, is used.

Syntax

PYTHON
BaseException.__context__

Examples

Example 1
PYTHON
raise new_exc from original_exc

See Also

except finally with raise from KeyError AttributeError None