title: How to throw an std::system_error exception from a FAILED(HRESULT)?
body: <p>This is <a href="https://stackoverflow.com/a/15855015/6923555">how to throw</a> ordinary Win32 errors correctly, automatically retrieving the error description, and it works marvellously well:</p>
  
  <pre><code>if (!SomeWinFunc()) {
    throw std::system_error(GetLastError(),
      std::system_category(),
      "SomeWinFunc crashed badly");
  }
  </code></pre>
  
  <p>However, I'm uncertain on how to deal with COM errors, which are checked <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms693474(v=vs.85).aspx" rel="nofollow noreferrer">idiomatically</a> like this:</p>
  
  <pre><code>HRESULT hr = comObj-&gt;SomeFunc();
  if (FAILED(hr)) {
    throw std::system_error(hr, // &lt;-- is it correct here?
      std::system_category(),
      "SomeFunc crashed right now");
  }
  </code></pre>
  
  <p>Is it correct to pass an <code>HRESULT</code> to <code>system_error</code>, or there is another way to throw exceptions from a COM function?</p>