title: How is a StackOverflowException detected?
body: <p>TL;TR<br>
  When I asked the question I assumed a <code>StackOverflowException</code> is a
  mechanism to prevent applications to run infinitely. This is not true.<br>
  <strong>A <code>StackOverflowException</code> is not being detected.<br>
  It is thrown when
  the stack does not have the capacity to allocate more memory.</strong></p>
  
  <p>[Original question:]</p>
  
  <p>This is a general question, which may has different answers per programming language.<br>
  I am unsure how languages other than C# process a stack overflow.</p>
  
  <p>I was going through exceptions today and kept thinking about how a <code>StackOverflowException</code> can be detected. I believe it is not possible to say f.e. if the stack is 1000 calls deep, then throw the exception. Because maybe in some cases the correct logic will be that deep.</p>
  
  <p><strong>What is the logic behind the detection of an infinite loop in my program?</strong></p>
  
  <p><code>StackOverflowException</code> class:<br>
  <a href="https://msdn.microsoft.com/de-de/library/system.stackoverflowexception%28v=vs.110%29.aspx" rel="noreferrer">https://msdn.microsoft.com/de-de/library/system.stackoverflowexception%28v=vs.110%29.aspx</a><br><br>
  Cross reference mentioned in the <code>StackOverflowException</code> class documentation:<br>
  <a href="https://msdn.microsoft.com/de-de/library/system.reflection.emit.opcodes.localloc(v=vs.110).aspx" rel="noreferrer">https://msdn.microsoft.com/de-de/library/system.reflection.emit.opcodes.localloc(v=vs.110).aspx</a><br></p>
  
  <p>I just added the <code>stack-overflow</code> tag to this question, and the description says it is being thrown when the call stack consumes too much memory. Does that mean the call stack is some sort of path to the current executing position of my program and if it cannot store more <em>path information</em>, then the exception is thrown?</p>