title: How to catch exception from CloseHandle()
body: <p>As of the MSDN spec, <code>CloseHandle</code> throws an Exception if an invalid handle is passed to it when it runs under a debugger.</p>
  
  <p>Since I want to have clean code, I've inserted some code to catch it. However, it doesn't work, the exception gets uncaught.</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;tchar.h&gt;
  #include &lt;exception&gt;
  /* omitted code */
  CloseHandle(myHandle); // close the handle, the handle is now invalid
  try {
      success = CloseHandle(myHandle);
  } catch (std::exception&amp; e) {
      _tprintf(TEXT("%s\n"), e.what());
  } catch (...) {
      _tprintf(TEXT("UNKNOWN\n"));
  }
  </code></pre>
  
  <p>I get the following two errors from the debugger:</p>
  
  <blockquote>
    <p>First-chance exception: 0xC0000008: An invalid handle was specified.</p>
    
    <p>Uncaught exception: 0xC0000008: An invalid handle was specified.</p>
  </blockquote>
  
  <p>I think that the first-chance exception is normal, since it gets fired before the catch statement should get it. However, the uncaught exception makes me wondering what's actually wrong here.</p>