title: What actually causes a Stack Overflow error?
body: <p>I've looked everywhere and can't find a solid answer. According to the documentation, Java throws a <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/StackOverflowError.html">java.lang.StackOverflowError</a> error under the following circumstance:</p>
  
  <blockquote>
    <p>Thrown when a stack overflow occurs because an application recurses too deeply.</p>
  </blockquote>
  
  <p>But this raises two questions:</p>
  
  <ul>
  <li>Aren't there other ways for a stack overflow to occur, not only through recursion?</li>
  <li>Does the StackOverflowError happen before the JVM actually overflows the stack or after?</li>
  </ul>
  
  <p>To elaborate on the second question:</p>
  
  <p>When Java throws the StackOverflowError, can you safely assume that the stack did not write into the heap? If you shrink the size of the stack or heap in a try/catch on a function that throws a stack overflow, can you continue working? Is this documented anywhere?</p>
  
  <p>Answers I am not looking for:</p>
  
  <ul>
  <li>A StackOverflow happens because of bad recursion.</li>
  <li>A StackOverflow happens when the heap meets the stack.</li>
  </ul>