try:
recursive_function()
except RuntimeError e:
# is this a max. recursion depth exceeded exception?
How do I tell when the maximum recursion depth has been reached?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can look inside the exception itself:
I don’t think you can distinguish between this and something merely pretending to be a recursion-depth-exceeded (Runtime) exception, though.
messageis deprecated, soargsis probably the best bet, and is Python-3 compatible.Update: in Python 3.5, there’s a specific
RecursionErrorwhich you can catch instead.