参数b是显示catch到的错误后的后续处理代码
参数c是数据库连接指针_ConnectionPtr的对象,用于捕捉数据库错误消息
其中用到的下面两个函数,见本专栏其他文章。
- GetProviderError(_ConnectionPtr)
- <pre name="code" class="cpp">GetComError(_com_error &e)</pre>
- <pre></pre>
- <p></p>
- <pre></pre>
- <p></p>
- <p>#define MYCATCH(b,c) \</p>
- <p></p>
- <pre name="code" class="cpp"> 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\
- }</pre><br>
- <br>
- <p></p>
|