all Python 3Exceptionsexception
RuntimeError
built-in exceptions
A generic runtime error that doesn't fit other categories.
Syntax
raise RuntimeError
Using it as a catch-all is a trap: RecursionError and NotImplementedError are subclasses, so except RuntimeError swallows them too. It also arrives from very concrete situations — dictionary changed size during iteration when you mutate a dict inside a loop over it, or generator raised StopIteration. Raise your own only when no more specific exception class fits.
Examples
try:
raise RuntimeError
except RuntimeError as e:
print(type(e).__name__) # → RuntimeError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy