title: SEH StackOverflow exception - is it real not possible to catch?
body: <p>I have read many articles about <code>SEH exceptions</code> in StackOverflow and CodeProject.net.</p>
  
  <p>After I implemented <code>SEH exceptions</code> handling in my C++ program, I was affected by stack overflow exception, which hadn't been caught by my software. </p>
  
  <p>After next part of research I understand, that it's impossible to detect such exception programmatically, because we don't have free stack address space to use, so program memory is corrupted.</p>
  
  <p>I would like to ask you about your experience in handling stack overflow exception. It looks like a challenge and I'm really interested if it's not possible in unmanaged code programming languages?</p>
  
  <p>Below I present a part of my sample program (C++), which reproduces <code>stack overflow exception</code>. It works perfectly for any <code>SEH exception</code>, but not stack overflow:</p>
  
  <pre><code>LONG WINAPI SehHandler(PEXCEPTION_POINTERS pExceptionPtrs)
  { 
      cerr &lt;&lt; "Handled SEH exception!\n";
      cerr &lt;&lt; "ContextRecord: " &lt;&lt; pExceptionPtrs-&gt;ContextRecord &lt;&lt; endl;
      cerr &lt;&lt; "ExceptionRecord: " &lt;&lt; pExceptionPtrs-&gt;ExceptionRecord &lt;&lt; endl;
  
      // Write minidump file
      CreateMiniDump(pExceptionPtrs);
  
      // Terminate process
      TerminateProcess(GetCurrentProcess(), 1); 
  
      return EXCEPTION_EXECUTE_HANDLER;
  }
  
  int fib(unsigned int n) {
      if(n == 0) return 0;
      if(n == 1) return 1;
      return fib(n-1)+fib(n-2);
  }
  
  int main(){
      SetUnhandledExceptionFilter(SehHandler); 
      cout &lt;&lt; fib(1000000);
      return 0;
  }
  </code></pre>