Re: CFile does not throw exception.
kiran,
Thank you, but that's not the problem. It's only my typo. It seems that
CFile::Open(..)does not throw an exception for "try - catch" logic.
Best regards,
Baker Huang
kiran.inbng@gmail.com =E5=86=99=E9=81=93=EF=BC=9A
Hi Baker,
Only problem i find in the above code is that exception parameter
passed to the file.open is not the correct one,apart from that i dont
see any problem with the code.
-Kiran
Baker wrote:
Experts,
I am using CFile class to do file reading and writing operation. I use
the following codes to catch a CFileException when open up a file:
CFile fScr;
CFileException fEx;
if(!fSrc.Open(_T("c:\\1.txt"),CFile::modeRead,&m_fEx))
{
fEx.ReportError();
// Then write code to abort operation
}
This code will catch the file access violation exception, meaning that
when the target file is already opened, then CFile::Open(,,,) will
return FALSE and the code will report error.
But, when there is no "c:\1.txt" file exists, the apllication will have
a run time error saying that there is "an unhandled exception". This
means that the above code can not catch all the CFileException during
file openning.
Do you have any idea of making CFile throwing and catch all types of
CFileException?
Thanks,
Baker Huang