A good article, definition, or discussion that explains RuntimeError: maximum recursion depth exceeded


In trying to help this guy out in this forum post Here I was looking for a good article/definition/example of RuntimeError: maximum recursion depth exceeded but failed to find one just by googling it. I see this error come up enough times that I think it would be worth compiling at least a good definition on this subject so it can be reference to help others understand when this issue occurs.


Hmmm. I was just talking about maximum recursion depth yesterday in this lovely topic. I don't know exactly how to describe everything, but reading this might help even though I probably don't know what I'm talking about. Maybe @appylpye could share some insight on this error?


Yeah I saw that discussion and I think it could help but what I had "envisioned" for this might be something to this nature:


what causes this

how to go about fixing it

link example in discussion or other website to go along with the discussion here

Maybe its a little much but I know I would have loved something like this when I encountered this particular error. It would be a logical way to learn, understand, and see what the error being dealt with in a proper manner.


do you know what recursion is? There must be good articles about recursion itself.

recursion can be very useful (listing all directory's + sub directory's in the current directory), you can also have recursion with function calls, the definition of recursion:

Recursion occurs when a thing is defined in terms of itself or of its type

well a function calling itself it is basically defined in terms of itself.

the problem is, if you don't make the recursion stop, it will go on endlessly, sort of like a infinity loop but different


I see what you're saying. It was only barely related, but I wasn't sure if you just wanted a very simple explanation. I did tag someone that might know more about it, but I'll be right back let me see what I can find. :slight_smile:


Yeah I understand recursion. However, I did not really have a good way to explain like you have. Also, I was hoping to specifically define and discussion the error in itself because I know it is not something that is just a basic error that new learners can just decipher on their own. So an explanation of the error itself in a format like I suggest above would I believe be quite useful.


What I'm really finding, is just that this happens when you don't put a stop condition in the function to stop the recursion.
This is what I've found so far:
The What, How, and When of Recursion

Alright dude, I don't know how much this will actually help. I just notice that it's an error that happens during infinite recursion, or when there is a set depth that the user runs past such as in the last picture.
(peep my terminal and jGRASP apps) :slight_smile:


Yeah the problem is there is just not something that is as straight forward to what I was hoping to find unless I or someone else creates it xD So if I get sometime I might try to compile something like I was hoping to find and get others to review it so I can know what I am saying makes sense and is correct.


You're right! :slight_smile: Sorry I can't be of more help, I just don't have much experience with the error. (Or with any error for that matter, I don't know too much about the logic behind programming besides the obvious.)



Recursion occurs when a thing is defined in terms of itself (wikipedia - recursion)

what causes this

in most cases this will be caused by a function calling itself, causing a sort of infinity loop but then with function calls

how to go about fixing it

look for your function calls, might any of them be nested inside a function?

for example (js):

function example(){
   console.log("recursion function calls");
   //the function will endlessly keep calling itself 
   // because the function call is nested inside the function


def example():
   print "recursion function calls"
  # the function will endlessly keep calling itself
  # because the function call is nested inside the function


Once again @stetim94 is my hero! Haha. Thank you! That looks really nice!


Your fine! I don't either. Really what I am going for is just a practical look at the error what is how to fix it etc and seemingly @stetim94 has done that. I might still try to find article on the specific error but for just general purposes I think he nailed it.


Yes he has! I'm super happy about that. When is @stetim94 not amazing?! Seriously dude, we want to be you. :slight_smile:


as for the error, in case of python it seems to be a safe guard:

i once watched a video about stackoverflow attacks (i believe it was CS50 introduction to computer science on edx), but it is to long ago.

so the error is caused by something built into the programming language, in essence it boils down to the fact that the function is called so often, an error is returned.

maximum recursion depth = maximum number of recursion function calls occurred (sort of)

@kyleaw, just like everyone i started from scratch (lol, before i came to codecademy i had no idea what a programming language was). So i guess everyone can achieve my level, given enough time and effort