This documentation is archived and is not being maintained.

CFile::Abort

Closes the file associated with this object and makes the file unavailable for reading or writing.

virtual void Abort( );

Remarks

If you have not closed the file before destroying the object, the destructor closes it for you.

When handling exceptions, CFile::Abort differs from CFile::Close in two important ways. First, the Abort function will not throw an exception on failures because failures are ignored by Abort. Second, Abort will not ASSERT if the file has not been opened or was closed previously.

If you used new to allocate the CFile object on the heap, then you must delete it after closing the file. Abort sets m_hFile to CFile::hFileNull.

Example

//example for CFile::Abort
CStdioFile fileTest;
char* pFileName = "test.dat";
TRY
{
   // do stuff that may throw exceptions
   fileTest.Open( pFileName, CFile::modeWrite );
}
CATCH_ALL( e )
{
   fileTest.Abort();   // close file safely and quietly
   THROW_LAST();
}
END_CATCH_ALL

See Also

CFile Overview | Class Members | Hierarchy Chart | CFile::Close | CFile::Open

Show: