Built-in Exceptions

SystemExit — exception class

sys.exit() raises this exception so cleanup can run before an uncaught exit terminates the process. Its code attribute stores the requested status or message; None normally means success. Catching it prevents that exit from propagating.

Formal Syntax & Structure

python syntaxpython
SystemExit

Return Value

type

The class object SystemExit; this reference documents the class identity, not a universal constructor signature.

Working Example

Example Snippetpython
import systry:    sys.exit(2)except SystemExit as error:    print(type(error).__name__)
Python Reference