Microsoft Visual C++ MFC. Win95 WinNT


Except


Except, 3.3, . try CMemoryException, CFileException, CException, . try , , catch. , CException, CArchiveException, CNotSupportedException CResourceException, catch CException. , CException, catch.

3.3. Except.cpp

#include "stdafx.h"

 

int WINAPI WinMain(

HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nShowCmd

)

{

try

{

CFile file("This file is absent", CFile::modeRead);

// ,

//

}

 

// CMemoryException

catch(CMemoryException* ptrException)

{

MessageBox(NULL,"Memory Exception", "Exception",

MB_OK | MB_ICONSTOP);

 

ptrException -> Delete();

}

 

// CFileException

catch(CFileException* ptrException)

{

if(ptrException -> m_cause ==

CFileException::fileNotFound)

MessageBox(NULL,"File Not Found", "Exception",