将VC6转换为VS2008时尝试捕获时出错

时间:2010-10-06 05:04:36

标签: c++ windows exception mfc cexception

当我在VS2008中打开VC6项目并尝试构建它时,我最初得到错误:

  

致命错误C1083:无法打开包含文件:'iostream.h':没有这样的文件或目录

     

错误C2259:'CException':无法实例化抽象类

     

错误BK1506:无法打开文件'。\ Debug \ SClientDlg.sbr':没有这样的文件或目录BSCMAKE SClient

现在我已将#include"iostream.h"更改为#include"iostream",现在获得7个错误(因为我已经尝试并抓住7个位置)说:

  

错误C2259:'CException':无法实例化抽象类

以下是该代码的摘录:

void SClientDlg::ProcessDomainName(int *m_pDlg,char* strDomainName,int iLen)
{
    try
    {
    //Do Something

    }
    catch(CException ex)
    {
        printf("Exception: %d",GetLastError()); 
    }


}

1 个答案:

答案 0 :(得分:4)

您可能需要这样做:

catch(CException& ex) // const& might be better

由于CException是抽象的,因此无法实例化它,但您可以引用从中派生的非抽象对象。