Click here to Skip to main content
15,881,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I am having following code in one class.While debugging in visual studio 6 ,after execution comes to line containing "LoadArchive.Close()" application crashes with errror as: Microsoft Visual C++ Runtime Library:

Runtime error.
Please provide me solution to thia problem. Thanks in advance.

CString sFilePath = "C://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/aa.NMF";
	try
	{
		
		
		CFile ScreenFile(sFilePath, CFile::modeRead | CFile::typeBinary );
		CArchive LoadArchive(&ScreenFile, CArchive::load, ScreenFile.GetLength());
		
		lResult = ReadDrawSO(LoadArchive);
		
		LoadArchive.Read(&m_VersionNo , sizeof(VERSION_NO_STRUCT));
		}
		
		
	
		LoadArchive.Close();
		
		ScreenFile.Close();
}       

	catch(CFileException* e)
	{
		DWORD dwError = GetLastError();
		if ( ERROR_FILE_NOT_FOUND == dwError)
		{
			CString sMsg;
			LOADSTRING( MESSAGE_STRING, IDS_STRING212, &sMsg );//IDS_STRING212 : "%s was not found."
			CString sError;
			sError.Format( sMsg, sFilePath );
			AfxMessageBox( sError );
		}
		e->Delete();
	}	
Posted
Comments
Jochen Arndt 26-Jan-12 5:44am    
Crashes it at or before the Close() command? The extra closing parenthesis '}' before the Close() command would produce a compiler error. If this is remaining from other code not shown here, the error may be sourced there.

As correctly noted by Jochen, you should get a compiler error similar to:
VB
Error   'LoadArchive' : undeclared identifier

(because LoadArchive is out of scope outside the try block).
If you don't, then there is another LoadArchive in your previous code and..., do you see the problem?
 
Share this answer
 
Oh actually by mistake i put closing parenthesis before "LoadArchive.Close()". Its not there. And my code gives runtime error while executing "LoadArchive.Close()" statement. Later i found it is throwing exception. So i put another try catch block for this statement. Now code is working fine. But i could not able to find exactly which exception it is throwing.
Thanks for comments.
 
Share this answer
 
Comments
Jochen Arndt 27-Jan-12 3:14am    
You should not pass such information as solution. You should edit your question and append this information prefixed with an update indicator (e.g. [UPDATE]).

You did not need another try catch block. You can use the existing one. With CFileException, you can add the values of the m_cause and lOsError members to your error message and show it always (not only upon ERROR_FILE_NOT_FOUND). When an exception is thrown and running the debug version of your program from the debugger, have also a look at the debug output to get some information about the exception.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900