Python Practice › sys Module Programs › Program 13
Recursion limit
Write a Python program that reads the recursion limit and handles RecursionError.
Output
1000 RecursionError caught
Approach
sys.getrecursionlimit().
Solution
import sys print(sys.getrecursionlimit()) def dive(n): return dive(n + 1) try: dive(0)except RecursionError: print("RecursionError caught")Output
1000 RecursionError caught
Learn the concept
New to this topic? Read the lesson, then come back.