马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Question
Where are the types of C++ exceptions for the LDDT COM interface defined? I want
to change the "catch (...)" statement to "catch (sometype*)".
Answer
_com_error object can be used for this aim. A _com_error object represents an
exception condition detected by the error-handling wrapper functions in the
header files generated from the type library or by one of the COM support
classes. The _com_error class encapsulates the HRESULT error code and any
associated IErrorInfo object. This applies generally to any COM interface, so it
is not specific to LDDT.
The similar is valid for the Err object in VB/A. There are also Source,
Description, Error (Number in VB/A) methods in it.
The following code shows how to use it in C++.
- void dump_com_error(_com_error &e)
- {
- _bstr_t bstrSource(e.Source());
- _bstr_t bstrDescription(e.Description());
- TCHAR szTemp[1024];
- CString csMsg = "COM error!\n";
- wsprintf(szTemp, _T("Code = %08lx\n"), e.Error());
- csMsg += szTemp;
- wsprintf(szTemp, _T("Code meaning = %s\n"), e.ErrorMessage());
- csMsg += szTemp;
- wsprintf(szTemp, _T("Source = %s\n"), bstrSource.length() ?
- (LPCTSTR)bstrSource : _T("null"));
- csMsg += szTemp;
- wsprintf(szTemp, _T("Description = %s\n"), bstrDescription.length() ?
- (LPCTSTR)bstrDescription : _T("null"));
- csMsg += szTemp;
- AfxMessageBox(csMsg);
- }
- void com_error_test()
- {
- try {
- // to do
- // ......
- }
- catch(_com_error& e) {
- dump_com_error(e);
- }
- }
|