This is how to throw ordinary Win32 errors correctly, automatically retrieving the error description, and it works marvellously well:
if (!SomeWinFunc()) {
throw std::system_error(GetLastError(),
std::system_category(),
"SomeWinFunc crashed badly");
}
However, I'm uncertain on how to deal with COM errors, which are checked idiomatically like this:
HRESULT hr = comObj->SomeFunc();
if (FAILED(hr)) {
throw std::system_error(hr, // <-- is it correct here?
std::system_category(),
"SomeFunc crashed right now");
}
Is it correct to pass an HRESULT
to system_error
, or there is another way to throw exceptions from a COM function?