怎样抛出异常 但发生错误,我是这样处理的throw new CException,但编译提示说CException,不能实例化抽象类。那该怎样抛出一个异常呢,谢谢了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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);#endifprotected: 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是个抽象类呢 简单问题 带vector的结构体,怎么作为dll的外接函数的参数? #include的一个奇怪问题 在MFC中创建向导应用程序碰到的问题? 求助:ocx打包成CAB文件(里面包含exe文件),项者有分..... 关于Ras连接状态问题 VB中的错误处理在VC中怎么实现 用VC SDK怎么加载'树型控件'? 怎么解决 这样的情况下 如何返回应用? SetROP2(R2_XORPEN)的实现机制问题? fatal error LNK1202 是什么意思?
{
// 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是个抽象类呢