Example & Tutorial understanding programming in easy ways.

What is StackOverflowError?

This is a very general concept. On Java, a StackOverflowError is thrown when the stack size is exceeded. This is an error, not an exception, because you are urged to avoid this situation, not recover from it.

Each time you call a function, a small piece of a special memory region - the stack - is allocated to it and holds the local variables and the context of the function. If our function calls another function, the next piece is cut off the stack and so on. The stack shrinks when a function returns again. If the nesting level becomes too high, it can overflow.

The typical example would be endless recursion:

public void foo(int i) {
  return foo(i+1);

Read More →