Home > Software engineering >  Trouble you to look at, under vs2015 catch (CFileException e) error, but no problem under vs2005, ho
Trouble you to look at, under vs2015 catch (CFileException e) error, but no problem under vs2005, ho

Time:11-21

 
//function function:
//open the file
//function input:
//char * pFileName
//file name
//CFile * pFile
//file handle
//int FileType
//0 source file, read-only file
//1 target files, create and write
//function returns:
//0 success
//1 pointer null
//2 abnormal file operations
//3 file open failed
Int OpenFileEx (char * pFileName, CFile * pFile, int FileType)
{
BOOL bRet=0;
CFileException e;
If ((pFileName==NULL) | | (pFile==NULL))
{
The return (1);
}
The else
{
Try
{
If (FileType==0)
{
BRet=pFile - & gt; Open (pFileName, CFile: : modeRead | CFile: : typeBinary, & amp; E);
}
The else
{
BRet=pFile - & gt; Open (pFileName, CFile: : modeCreate | CFile: : modeWrite, & amp; E);
}
If (bRet==TRUE)
{
Return (0);
}
The else
{
Return (3);
}
}
The catch (CFileException e)
{
Return (2);
}
}
}




Error message:
Error C2316: "CFileException" : not as a destructor, copy constructor or inaccessible or deleted, or at the same time appear in both cases


CodePudding user response:

Find a solution, will catch (CFileException e) into the catch (CFileException * e),


Does anyone know why this is?





CodePudding user response:

 
Void AFXAPI AfxThrowFileException (int cause, LONG lOsError,
LPCTSTR lpszFileName==NULL/* */)
{
# ifdef _DEBUG
LPCSTR LPSZ;
If (cause & gt;=0 & amp; & Cause & lt; _countof (rgszCFileExceptionCause))
LPSZ=rgszCFileExceptionCause [cause].
The else
LPSZ=szUnknown;
TRACE3 (" CFile exception: % hs, the File % s, OS error information=% ld. \ n ",
LPSZ, (lpszFileName==NULL)? _T (" Unknown ") : lpszFileName, lOsError);
# endif
THROW (new CFileException (cause, lOsError lpszFileName));
}

CodePudding user response:

Can you under the specific said, a bit not understand




CodePudding user response:

CFile delivery CFileException is new out
Also catch also corresponds to the Delete
 
Try
{
//Do something to throw a file exception.
}
The catch (CFileException * theException)
{
If (theException - & gt; M_cause==CFileException: : fileNotFound)
TRACE (" File not found \ n ");
TheException - & gt; The Delete ();
}

  • Related