_RecordsetPtr pRecordsetPtr;
pRecordsetPtr.CreateInstance(__uuidof(Recordset));
try
{
CString strSQL = "SELECT * FROM ABC";
pRecordsetPtr->Open(strSQL.GetBuffer(), theApp.m_ConnectionPtr.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch (_com_error e)
{
MessageBox(e.ErrorMessage(), "提示信息");
}实际上abc这个表并不存在,那么应该如何捕获这个异常?
pRecordsetPtr.CreateInstance(__uuidof(Recordset));
try
{
CString strSQL = "SELECT * FROM ABC";
pRecordsetPtr->Open(strSQL.GetBuffer(), theApp.m_ConnectionPtr.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch (_com_error e)
{
MessageBox(e.ErrorMessage(), "提示信息");
}实际上abc这个表并不存在,那么应该如何捕获这个异常?
#if !defined CATCH_ERROR
#define CATCH_ERROR \
{ \
CString strComError; \
strComError.Format("错误编号: %08lx\n错误信息: %s\n错误源: %s\n错误描述: %s", \
e.Error(), \
e.ErrorMessage(), \
(LPCSTR) e.Source(), \
(LPCSTR) e.Description()); \
::MessageBox(NULL,strComError,"错误",MB_ICONEXCLAMATION); \
}
#endif
{
……
}
catch(_com_error e)///捕捉异常
{
CATCH_ERROR;
return false;
}