다음을 통해 공유


CException::Delete

이 함수 인지 확인 하는 CException 객체는 힙에 생성 한 경우이 호출의 삭제 연산자는 개체에서.

void Delete( );

설명

삭제 하는 넓습니다 개체, 사용의 삭제 멤버 함수는 예외를 삭제 합니다.사용 하지 않는 삭제 연산자를 직접 때문에 CException 개체는 전역 개체 이거나 스택에 만들어졌습니다.

개체를 생성할 때 개체를 삭제 여부를 지정할 수 있습니다.자세한 내용은 CException::CException.

호출 하면 삭제 는 C++를 사용 하는 경우 시도-catch 메커니즘.MFC 매크로 사용 하는 경우 시도CATCH,이 매크로 자동으로이 함수를 호출 하 고 있습니다.

예제

CFile* pFile = NULL;

// Constructing a CFile object with this override may throw
// a CFile exception, and won't throw any other exceptions.
// Calling CString::Format() may throw a CMemoryException,
// so we have a catch block for such exceptions, too. Any
// other exception types this function throws will be
// routed to the calling function.

// Note that this example performs the same actions as the 
// example for CATCH, but uses C++ try/catch syntax instead
// of using the MFC TRY/CATCH macros. This sample must use
// CException::Delete() to delete the exception objects
// before closing the catch block, while the CATCH example
// implicitly performs the deletion via the macros.

try
{
   pFile = new CFile(_T("C:\\WINDOWS\\SYSTEM.INI"),
      CFile::modeRead | CFile::shareDenyNone);

   ULONGLONG ullLength = pFile->GetLength();

   CString str;
   str.Format(_T("Your SYSTEM.INI file is %u bytes long."), ullLength);

   AfxMessageBox(str);
}
catch(CFileException* pEx)
{
   // Simply show an error message to the user.

   pEx->ReportError();
   pEx->Delete();
}
catch(CMemoryException* pEx)
{
   // We can't recover from this memory exception, so we'll
   // just terminate the app without any cleanup. Normally, an
   // an application should do everything it possibly can to
   // clean up properly and _not_ call AfxAbort().

   pEx->Delete();
   AfxAbort();
}

// If an exception occurrs in the CFile constructor,
// the language will free the memory allocated by new
// and will not complete the assignment to pFile.
// Thus, our clean-up code needs to test for NULL.

if (pFile != NULL)
{
   pFile->Close();
   delete pFile;
}   

요구 사항

헤더: afx.h

참고 항목

참조

CException 클래스

계층 구조 차트