开发者

Getting error message from CStdioFile::Open()?

开发者 https://www.devze.com 2023-01-09 11:05 出处:网络
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:

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

精彩评论

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

关注公众号