请教一下,CFile类的Open的异常怎么样捕获?CFileException exp;
BOOL bOK = file.Openm_strFilePath,CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate|CFile::shareDenyNone,&exp );
if ( !bOK )
{
switch (exp.m_cause)
    {
case CFileException::tooManyOpenFiles :
AfxMessageBox("The permitted number of open files was exceeded");
break;
default:
AfxMessageBox("文件操作发生错误");

    }
}
{这样用有问题么?
为什么 还是在open这里有 unhandled exception
谢谢了

解决方案 »

  1.   

     CFile file;
      CFileException exp;
    BOOL bOK = file.Open("C:\\1.txt",CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate|CFile::shareDenyNone,&exp    );
    if ( !bOK )
    {
    switch (exp.m_cause)
    {
    case CFileException::tooManyOpenFiles :
    AfxMessageBox("The permitted number of open files was exceeded");
    break;
    default:
    AfxMessageBox("文件操作发生错误");
                
    }
    }我测试了一下是OK的,你查看你的文件名字了,看能有问题。
      

  2.   

    文件路径 肯定是对的, 
    但是 如果是文件路径是错的,是不是在执行open时也应该能捕获异常?
    不知道为什么 open时 异常捕获不了,一直在弹unhandled exception 的对话框
      

  3.   

    嗯,谢谢了
    我觉得也是正确的,但是不知道在运行时出错,debug下定位到open函数,弹unhandled exception 的对话框 
    不知道为什么这个 异常捕获不了,
      

  4.   


    CFileException exp;
    try{
    file.Open(m_strFilePath,CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate|CFile::shareDenyNone,&
    }
    catch(CFileException * exp){ 
    exp->ReportError(); 
    exp->Delete(); 
    }
    }
    跟踪看一下路径格式有没有问题
      

  5.   

    这个到不了 catch ,直接在open 就停下了,路径没有问题啊