none
CFileException - I don't understand the exception

    Question

  • Hello. I am trying to save a file using CFile.

    The basic code looks like this:

                      CFile file;
    		CFileException fe;
    		bool bFileOpen = file.Open(filename, CFile::modeCreate | CFile::modeWrite, &fe);
    		CDib dib;
    		CDib cropdib;
    		CDib* pSaveDib = &dib;
    		dib.Read24FromBuffer8(nWidth,nHeight,m_SaveBMPBuff);
    		TRY
    		{
    			pSaveDib->Save(file);
    		}
    		CATCH(CFileException, e)
    		{
    	
    			if( e->m_cause == CFileException::fileNotFound )
    				AfxMessageBox("File not found!");
    			else if ( e->m_cause == CFileException::badPath )
    				AfxMessageBox("Bad Path!"); 
    			else if ( e->m_cause == CFileException::genericException )
    				AfxMessageBox("An unspecified error occured!"); 
    			else if ( e->m_cause == CFileException::accessDenied)
    				AfxMessageBox("The file could not be open!"); 
    			else if ( e->m_cause == CFileException::invalidFile )
    				AfxMessageBox("Invalid File!"); 
    			else if ( e->m_cause == CFileException::removeCurrentDir)
    				AfxMessageBox("The current directory cannot be removed!");
    			else if ( e->m_cause == CFileException::diskFull)
    				AfxMessageBox("The disk is full!"); 
    			else if ( e->m_cause == CFileException::endOfFile)
    				AfxMessageBox("Fin du fichier!"); 
    			else if (e->m_cause == CFileException::lockViolation)
    				AfxMessageBox("Lock Violation!");
    			else if (e->m_cause == CFileException::sharingViolation)
    				AfxMessageBox("Sharing Violation!");
    			// Simply show an error message to the user.
    			else 
    				AfxMessageBox("Une erreur de merde est survenue");
    		
    		}
    		END_CATCH
    	}

     The pSaveDib->Save(file); does  file.Write(m_pBMI, nCount);

    I get an error:  CFileException::fileNotFound

    I have had this code for almost a year -- without error. I did something that is causing this to happen. I am not sure what "file not found" could possibly mean when I am telling it to write the file, and the file indeed is opening

    file.Open(filename, CFile::modeCreate | CFile::modeWrite, &fe); is not returning an error.

    Any ideas?

     

     

     

    Wednesday, April 14, 2010 3:48 PM

Answers

  • Superman:

    I appreciate your answering.

    Well the truth is that I did figure out the problem. And it was a pretty difficult bug to fix -- it seems that in fact the file was "already open" because I had a copy-paste error that I did not show in the post (luckly because I would be embarrassed).

    I have figured this out already.

    Is there a way that I can "close" this case so that others don't have to waste their time over this?

    Thanks

     

     

    • Marked as answer by CPPPerson Sunday, April 18, 2010 4:36 AM
    Wednesday, April 14, 2010 7:50 PM

All replies

  • You could check if the path you're writing to is write protected or if the disk is full.
    «_Superman_»
    Microsoft MVP (Visual C++)
    Wednesday, April 14, 2010 4:40 PM
  • Superman:

    I appreciate your answering.

    Well the truth is that I did figure out the problem. And it was a pretty difficult bug to fix -- it seems that in fact the file was "already open" because I had a copy-paste error that I did not show in the post (luckly because I would be embarrassed).

    I have figured this out already.

    Is there a way that I can "close" this case so that others don't have to waste their time over this?

    Thanks

     

     

    • Marked as answer by CPPPerson Sunday, April 18, 2010 4:36 AM
    Wednesday, April 14, 2010 7:50 PM
  • Hi CPPPerson

    To close this issue, you can simply mark your last reply as Ansewer.

    Cheers

    Yi Feng Li


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, April 16, 2010 7:17 AM