Created
February 14, 2011 02:25
-
-
Save thinkhy/825401 to your computer and use it in GitHub Desktop.
Windows COM异常处理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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