Exception Attributes
BaseException.__cause__ — exception attribute
Inspect an explicitly attached cause, usually created with raise ... from original. Setting a cause also enables context suppression. Using from None hides the implicit context in normal traceback rendering but does not erase it. The cause must be an exception instance or None when assigned directly.
Formal Syntax & Structure
python syntaxpython
error.__cause__Return Value
BaseException | None
Explicit cause or None.
Working Example
Example Snippetpython
try: try: int("bad") except ValueError as original: raise RuntimeError("configuration") from originalexcept RuntimeError as error: print(type(error.__cause__).__name__) print(error.__cause__ is error.__context__)