从 CStdioFile::Open() 获取错误消息?
如果 CStdioFile::Open 失败,我希望能够报告错误原因。
然而,它似乎永远不会抛出异常。另外,当我尝试以下操作时:
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);
断言在 exc.GetErrorMessage: 中的某处被触发,
ASSERT(afxCurrentResourceHandle != NULL);
我读到当我不使用 try-catch 块时会发生这种情况。但是,当 Open 不抛出任何异常时,为什么要使用 try-catch 块呢?
任何有关如何报告打开错误的想法都会很有帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论