RecursionError in Python — What It Means and How to Fix It
What Python's RecursionError exception means and how to resolve it.
Published October 28, 2026
RecursionError is raised when a function calls itself too many times, exceeding Python's maximum recursion depth.
Key points
- Catch it specifically with "except RecursionError:" when you want to handle this exact case rather than a bare except
Example
def f(): return f()\nf() # RecursionError: maximum recursion depth exceeded