Each time you call a function, it is allocated a small piece of a special area of โโmemory - the stack and contains local variables and the context of the function. If our function calls another function, the next part cuts off the stack and so on. The stack is reset when the function returns again. If the nesting level becomes too high, it can overflow.
This is a very general concept. In Java, when the stack size is exceeded, a StackOverflowError . This is a mistake , not an exception , because you are strongly advised to avoid this situation and not recover from it.
A typical example is infinite recursion:
public void foo(int i) { return foo(i+1); }
source share