2

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!

des4maisons
  • 1,791
  • 4
  • 20
  • 23

1 Answers1

1

See CStdioFile::CStdioFile examples.

adf88
  • 4,277
  • 1
  • 23
  • 21
  • 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 Jul 26 '10 at 19:50
  • 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 Jul 27 '10 at 13:00