以文件为例:
CFile( LPCTSTR lpszFileName, UINT nOpenFlags );
throw( CFileException );//example for CFile::CFile
char* pFileName = "test.dat";
TRY
{
CFile f( pFileName, CFile::modeCreate | CFile::modeWrite );
}
CATCH( CFileException, e )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e->m_cause << "\n";
#endif
}
END_CATCH
CFile( LPCTSTR lpszFileName, UINT nOpenFlags );
throw( CFileException );//example for CFile::CFile
char* pFileName = "test.dat";
TRY
{
CFile f( pFileName, CFile::modeCreate | CFile::modeWrite );
}
CATCH( CFileException, e )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e->m_cause << "\n";
#endif
}
END_CATCH
我说得是window C++ exception
比如这里_variant_t vUsername = m_pResultRecordset->GetCollect("username");
if(vUsername.vt == VT_NULL) {
m_pResultRecordset->MoveNext();
continue;
} else {
LPCSTR temp = _bstr_t(vUsername);
CString strName = (LPCSTR)_bstr_t(vUsername);
}
如果不判断
vUsername.vt == VT_NULL而直接
LPCSTR temp = _bstr_t(vUsername);
CString strName = (LPCSTR)_bstr_t(vUsername);
就会导致错误但是try {
_variant_t vUsername = m_pResultRecordset->GetCollect("username");
if(vUsername.vt == VT_NULL) {
LPCSTR temp = _bstr_t(vUsername);
CString strName = (LPCSTR)_bstr_t(vUsername);
}
} catch( ???? ) {
e.setMessage("vUsername.vt == VT_NULL");
}并不能捕捉阿
操作系统 winXP -sp2
怎么做啊?
try
{
// 代码
}
catch(...)
{
// 代码
}
这个???代表什么?
CObject o?
当id 为空的时候 查询就会出现上面的异常
我现在的处理方法是前期处理
if(su.isNull(id)) {
MessageBox("请输入要查询的id");
return;
}
但是我想后期处理
try {
m_pRecordset = theApp.m_pConnection->Execute((_bstr_t)("select * from users where id = " +id),&RecordsAffected,adCmdText);
} catch(....) {
MessageBox("很抱歉,查询失败!");
}只是无法捕捉此异常