但发生错误,我是这样处理的throw new CException,但编译提示说CException,不能实例化抽象类。那该怎样抛出一个异常呢,谢谢了。

解决方案 »

  1.   

    class AFX_NOVTABLE CException : public CObject
    {
    // abstract class for dynamic type checking
    DECLARE_DYNAMIC(CException)public:
    // Constructors
    CException();   // sets m_bAutoDelete = TRUE
    explicit CException(BOOL bAutoDelete);   // sets m_bAutoDelete = bAutoDelete// Operations
    void Delete();  // use to delete exception in 'catch' block virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
    PUINT pnHelpContext = NULL);
    virtual int ReportError(UINT nType = MB_OK, UINT nMessageID = 0);// Implementation (setting m_bAutoDelete to FALSE is advanced)
    public:
    virtual ~CException() = 0;
    BOOL m_bAutoDelete;
    #ifdef _DEBUG
    void PASCAL operator delete(void* pbData);
    #if _MSC_VER >= 1200
    void PASCAL operator delete(void* pbData, LPCSTR lpszFileName, int nLine);
    #endif
    protected:
    BOOL m_bReadyForDelete;
    #endif
    };
    对于CException在except.cpp里已经实现了其相应的虚函数了啊
    CException::CException()
    {
    // most exceptions are deleted when not needed
    m_bAutoDelete = TRUE;
    #ifdef _DEBUG
    m_bReadyForDelete = FALSE;
    #endif
    }CException::CException(BOOL bAutoDelete)
    {
    // for exceptions which are not auto-delete (usually)
    m_bAutoDelete = bAutoDelete;
    #ifdef _DEBUG
    m_bReadyForDelete = FALSE;
    #endif
    }void CException::Delete()
    {
    // delete exception if it is auto-deleting
    if (m_bAutoDelete > 0)
    {
    #ifdef _DEBUG
    m_bReadyForDelete = TRUE;
    #endif
    delete this;
    }
    }BOOL CException::GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
    PUINT pnHelpContext /* = NULL */ )
    {
    if (pnHelpContext != NULL)
    *pnHelpContext = 0; if (nMaxError != 0 && lpszError != NULL)
    *lpszError = '\0'; return FALSE;
    }int CException::ReportError(UINT nType /* = MB_OK */,
    UINT nError /* = 0 */)
    {
    TCHAR   szErrorMessage[512];
    int     nDisposition;
    UINT    nHelpContext; if (GetErrorMessage(szErrorMessage, _countof(szErrorMessage), &nHelpContext))
    nDisposition = AfxMessageBox(szErrorMessage, nType, nHelpContext);
    else
    {
    if (nError == 0)
    nError = AFX_IDP_NO_ERROR_AVAILABLE;
    nDisposition = AfxMessageBox(nError, nType, nHelpContext);
    }
    return nDisposition;
    }
    怎么还说CException是个抽象类呢