title: One Valid Case of Exception leaving a Destructor
body: <p>I'm working on a simple class to manage the lifetime of a <code>HKEY</code>.</p>
  
  <pre><code>class Key
  {
      HKEY hWin32;
  public:
      Key(HKEY root, const std::wstring&amp; subKey, REGSAM samDesired);
      Key(const Key&amp; other);
      ~Key();
      Key&amp; operator=(const Key&amp; other);
      Key&amp; swap(Key&amp; other);
      HKEY getRawHandle() { return hWin32; };
  };
  
   //Other Methods....
  
  Key::~Key()
  {
      LONG errorCheck
          = RegCloseKey(hWin32);
      /*
       * I know it's generally bad to allow exceptions to leave destructors,
       * but I feel that if RegCloseKey() is going to fail, the application
       * should be terminated. (Because it should never fail.)
       */
      if (errorCheck != ERROR_SUCCESS)
          WindowsApiException::Throw(errorCheck);
  }
  </code></pre>
  
  <p>Is this valid reasoning? I don't see how else a failure of <code>RegCloseKey()</code> can be communicated to the callee.</p>