Exception Attributes
SystemExit.code — exception attribute
Inspect the requested process exit status or message. sys.exit() raises SystemExit rather than immediately terminating the interpreter; finally blocks can still run. If unhandled, None means success, an integer becomes an exit status, and another object is printed with failure status. The example catches SystemExit to avoid ending the test process.
Formal Syntax & Structure
python syntaxpython
error.codeReturn Value
object | None
Requested exit argument.
Working Example
Example Snippetpython
import systry: sys.exit(7)except SystemExit as error: print(error.code)print(SystemExit().code)