开发者

Getting error message from CStdioFile::Open()?

If CStdioFile::Open fails, I want to be able to report the cause of the error.

However, it appears as though it never throws an exception. Also, when I try the following:

CStdioFile file;

CFileException exc;
bool bSuccess = (file.Open(_T("FileDNE"), _O_RDONLY, &exc) == TRUE);
ASSERT_FALSE(bSuccess);

CString err;
exc.GetErrorMessage(err.GetBufferSetLength(255), 255);
std::cout << CStringA(err);

an assertion gets tripped somewhere low down in exc.GetErrorMessage:

ASSERT(afxCurrentResourceHandle != NULL);

I've read this happens when I don't use a try-开发者_开发百科catch block. But why use a try-catch block when Open doesn't throw any exceptions?

Any ideas on how to report Open errors would be helpful!


See CStdioFile::CStdioFile examples.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜