SystemError
Pure Python code should never be able to cause it. If you see one, look at the C extensions involved and their versions — and it is not SystemExit.
SystemError(*args)
Raised by
C extensions misusing the C API; interpreter bugs
Message
low-level, e.g. "<built-in function x> returned NULL without setting an exception"
Quick fix
upgrade/rebuild the extension for your Python version; report it
Watch out
not SystemExit — that is what sys.exit() raises
Constructor
| Name | Type | Required | Description |
|---|---|---|---|
| *args | object | no | A message in low-level terms describing what went wrong inside the interpreter. |
Attributes
| Attribute | Type | Meaning |
|---|---|---|
| args | tuple | The internal message, e.g. which function returned a bad result. |
Common patterns
Collect what the bug report needs
The docs ask for the interpreter version, the exact message and a way to reproduce.
import sys, platform print(sys.version) print(platform.platform()) # plus: pip freeze, the full traceback, a minimal script
Find the extension involved
The last frames of the traceback usually name the compiled module; faulthandler shows native crashes too.
import faulthandler faulthandler.enable()
Examples
1. Raise it (for illustration only)
raise SystemError('bad internal call')
Returns
SystemError: bad internal call2. An ordinary Exception subclass
issubclass(SystemError, Exception), issubclass(SystemError, RuntimeError)
Returns
(True, False)3. Not related to SystemExit
issubclass(SystemExit, Exception), issubclass(SystemError, Exception)
Returns
(False, True)4. Catchable like any Exception
try:
raise SystemError('internal')
except Exception as e:
kind = type(e).__name__
kind
Returns
'SystemError'Pitfalls
1. Mixing up SystemError and SystemExit
sys.exit() raises SystemExit, a BaseException that except Exception does NOT catch. SystemError is an interpreter bug report and IS an Exception.
except SystemError
import sys try: sys.exit(2) except SystemError: status = 'caught' except SystemExit as e: status = f'exit {e.code} went past except SystemError' status
'exit 2 went past except SystemError'
except SystemExit
import sys try: sys.exit(2) except SystemExit as e: status = f'caught exit {e.code}' status
'caught exit 2'
When to use
Use it
- Raising it from C extension code when an internal invariant of the extension breaks
Reach for something else
- Raising it from Python code — use RuntimeError or a custom exception
- Catching and ignoring it — it signals memory or interpreter state may be corrupt
Notes
CPython impl
Typical texts: "… returned NULL without setting an exception", "… returned a result with an exception set", "bad argument to internal function"
Usual cause
A compiled extension built for a different Python version, or with a C-API bug
Report to
the extension maintainer first; CPython (github.com/python/cpython/issues) if pure Python code triggers it
FAQ
SystemError signals a bug inside the interpreter or a C extension. Correct Python code has no reliable way to produce one — any snippet that did would be demonstrating a CPython bug that gets fixed. The examples raise it by hand to show its type and hierarchy instead.