16,472
社区成员
发帖
与我相关
我的任务
分享
#define MYCATCH(b,c) \
catch(const _com_error& e)\
{\
CString sBuff = GetProviderError(c);\
if(sBuff.IsEmpty())\
{\
sBuff=GetComError(e);\
}\
AfxMessageBox(sBuff);\
b\
}\
catch(COleException* e)\
{\
if(e)\
{\
CString szMsg;\
e->GetErrorMessage(szMsg.GetBuffer(255), 255);\
szMsg.ReleaseBuffer();\
AfxMessageBox(szMsg);\
e->Delete();\
}\
b\
}\
catch(COleDispatchException* e)\
{\
if(e)\
{\
AfxMessageBox(e->m_strDescription);\
e->Delete();\
}\
b\
}\
catch(CMemoryException* e)\
{\
if(e) e->Delete();\
AfxMessageBox(_T("Out-of-memory."));\
b\
}\
catch(LPCTSTR e)\
{\
AfxMessageBox(e);\
b\
}\
catch(...)\
{\
AfxMessageBox(TEXT("<Unexpected Error>"));\
b\
}
CString GetProviderError(_ConnectionPtr pConnection)
{
CString sErrors;
if(pConnection != NULL)
{
ADODB::ErrorsPtr ptrErrors = pConnection->Errors;
long lCount = ptrErrors->Count;
ADODB::ErrorPtr ptrError = NULL;
CString sError;
for(long n = 0; n < lCount; n++)
{
ptrError = ptrErrors->GetItem(n);
sError.Format(
_T("%s\nState: %s, Native: %d, Source: %s"),
(LPCTSTR)ptrError->Description,
(LPCTSTR)ptrError->SQLState,
ptrError->NativeError,
(LPCTSTR)ptrError->Source
);
sErrors += sError + TEXT("\n\n");
}
}
if(!sErrors.IsEmpty())
sErrors = sErrors.Left(sErrors.GetLength()-2);
return sErrors;
}