Skip to content

Instantly share code, notes, and snippets.

@thinkhy
Created February 14, 2011 02:25
Show Gist options
  • Save thinkhy/825401 to your computer and use it in GitHub Desktop.
Save thinkhy/825401 to your computer and use it in GitHub Desktop.
Windows COM异常处理
COM异常操作
try
{
}
catch (_com_error& ex)
{
CString strEX = ex.Description(); // 这个最重要的信息最终却没抛出去!
if (_TKLibrary::TK_CheckDebug())
::MessageBox(NULL, strEX, _T("数据库操作异常"), MB_OK );
bR = false;
}
更好的方式:
catch (_com_error& err)
{
_bstr_t desc = err.Description();
if (desc.length() > 0) {
::MessageBox(NULL, desc, _T("操作异常"), MB_OK );
} else {
const TCHAR * message = err.ErrorMessage();
if (message != NULL) {
::MessageBox(NULL, message, _T("操作异常"), MB_OK );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment