views:

76

answers:

1

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!

+1  A: 

See CStdioFile::CStdioFile examples.

adf88
After the call to open, I tried both _get_doserrno and _get_errno, using strerror to output them. In both cases, output is "No Error".
des4maisons
Thanks for answering, btw.
des4maisons
This should work, see my answer after edition.
adf88
I agree that this works, and I'll probably just do it this way. But is there really no good way to report errors with Open?
des4maisons