我的程序用catch(...){}能捕捉到一个错误,而用catc(CException *e){}却什么也捕捉不到,我想把用catch(...){}捕捉到的错误内容显示出来该怎么做啊

解决方案 »

  1.   

    CATCH(CFileException,e)
    {
    #ifdef _DEBUG
    afxDump<<"File could not be opened"<<e->m_cause<<"\n";
    #endif
    }
      

  2.   

    CException::GetErrorMessage

    CException::ReportError
      

  3.   

    关键是我用catch(...)时该如何显示错误信息,因为那个错误用catch(Exception e)捕捉不到阿
      

  4.   

    具体什么类型异常
    CMemoryException
    CFileException 
    CResourceException 
    COleException 
    CUserException 
      

  5.   

    Here is an example of the use of CException::GetErrorMessage.   CFile fileInput;
       CFileException ex;   // try to open a file for reading.
       // The file will certainly not
       // exist because there are too many explicit
       // directories in the name.   // if the call to Open() fails, ex will be
       // initialized with exception
       // information.  the call to ex.GetErrorMessage()
       // will retrieve an appropriate message describing
       // the error, and we'll add our own text
       // to make sure the user is perfectly sure what
       // went wrong.
       
       if (!fileInput.Open("\\Too\\Many\\Bad\\Dirs.DAT", CFile::modeRead, &ex))
       {
          TCHAR   szCause[255];
          CString strFormatted;      ex.GetErrorMessage(szCause, 255);      // (in real life, it's probably more
          // appropriate to read this from
          //  a string resource so it would be easy to
          // localize)      strFormatted = _T("The data file could not be opened because of this error: ");
          strFormatted += szCause;      AfxMessageBox(strFormatted);
       }
       else
       {
          // the file was opened, so do whatever work
          // with fileInput
          // we were planning...
          // :      fileInput.Close();
       }