Skip to content

Instantly share code, notes, and snippets.

@gchudnov
Created November 6, 2014 19:30
Show Gist options
  • Save gchudnov/7f723b9ed5772bcf7479 to your computer and use it in GitHub Desktop.
Save gchudnov/7f723b9ed5772bcf7479 to your computer and use it in GitHub Desktop.
Win32 COM exception handling
#include <iostream>
int main() {
try {
// ...
} catch(_com_error &e) {
_bstr_t source(e.Source());
_bstr_t description(e.Description());
std::wcout << L "Error: " << e.Error() << std::endl;
std::wcout << L "ErrorMessage: " << e.ErrorMessage() << std::endl;
std::wcout << L "Source: " << (!source ? L"" : static_cast <const wchar_t*>(source)) << std::endl;
std::wcout << L "Description: " <<(!description ? L"" : static_cast <const wchar_t*>(description)) << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment