c++ 下标越界的异常处理
vector<CString> paths;
CString str1=_T("1234");
CString str2=_T("2345");
paths.push_back(str1);
paths.push_back(str2);
CString str;
try
{
str=paths.at(0);
str=paths.at(1);
str=paths.at(2);
}
catch (CMemoryException* e)
{
AfxMessageBox(_T("an memeory error "));
}
catch (CFileException* e)
{
AfxMessageBox(_T("an fileexception error "));
}
catch (CException* e)
{
AfxMessageBox(_T("an error "));
}
AfxMessageBox(_T("Hello word"));
运行这段代码,程序崩溃了,我希望得到的结果是:当程序遇到下标越界时,爆出异常,返回false,但程序不能崩溃。