打开一个不存在的文件然后读,应该抛出异常,为什么不能catch? char Buf[1024];
CFileException e;
memset(Buf,0,1024);
try{
CFile hFile;
if (!hFile.Open("D:\\myfiles.xml",CFile::modeRead,&e))
; //不动作
// throw &e;
hFile.Read(Buf,30);
hFile.Close();
}catch(CFileException *e1) //为什么不能catch read函数抛出的异常?
{
e1->GetErrorMessage(Buf,1024);
}
catch(CException *ex)
{
ex->Delete();
}
((CWnd*)GetDlgItem(IDC_EDIT1))->SetWindowText(Buf);
CFileException e;
memset(Buf,0,1024);
try{
CFile hFile;
if (!hFile.Open("D:\\myfiles.xml",CFile::modeRead,&e))
; //不动作
// throw &e;
hFile.Read(Buf,30);
hFile.Close();
}catch(CFileException *e1) //为什么不能catch read函数抛出的异常?
{
e1->GetErrorMessage(Buf,1024);
}
catch(CException *ex)
{
ex->Delete();
}
((CWnd*)GetDlgItem(IDC_EDIT1))->SetWindowText(Buf);
里面已经指定抛出的异常对象,catch捕获不到省略掉
写成:hFile.Open("D:\\myfiles.xml",CFile::modeRead)