Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

First-chance exception problem?

Status
Not open for further replies.

ncwizad

Programmer
Aug 25, 2005
10
GB
Hi,
This code produces First-chance exception warnings on its last pass while reading the contents of the file m_IniFileName into the CString variable strAptLine.
ie.
CArchive exception: endOfFile.
First-chance exception in Prog.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
Code:
        CFile IniFile;
	CFileException Err;
	if(!IniFile.Open(m_IniFileName,CFile::modeRead,&Err) )
	{
		CString command;
		command.Format("Config File %s \ncould not be opened\nError no %i\n",m_IniFileName,Err.m_cause);
		MessageBox(command);
		return;
	}

	CArchive IniArch(&IniFile,CArchive::load);
	CArchiveException IniExn;

	while(IniArch.ReadString(strAptLine))
	{
.....
	}

	IniArch.Close();
	IniFile.Close();

Is this an error? and could it cause the full prog to give ASSERT errors when compiling the 'release' version?
(The 'debug' compile runs fine)
Is there another way of writing the code without the warnings?

Cheers
 
ASSERT (or assert) doesn't get compiled in release versions.

As long as the exceptions are being caught and handled somewhere, there shouldn't be a problem. You might want to step into the function where the exception is being thrown to find out what's causing it, but some badly written code might be using exceptions as a form of message passing instead of what they were designed for (which is error conditions only).

I got thousands of First Chance Exceptions on a project I was working on, but we couldn't do anything about them because a third party component we were using was abusing the exception handling system...
 
Thanks for that, but just to be sure i've rewritten the code using fopen() and fgets() which seems to solve my problems.
Code:
	FILE *IniFile;
	IniFile = fopen(m_IniFileName, "r");
	if (IniFile == NULL)
	{
		command.Format("%s","Cannot Open Config File: %s",m_IniFileName);
		MessageBox(command,"Error",MB_ICONEXCLAMATION);
		fclose(IniFile);
		return;
	}
	char tmpline[152] = {'\0'};
	while(!feof(IniFile))
	{
	        fgets(tmpline,152,IniFile);
		aptline.Format("%s",tmpline);
...
...
	}
	fclose(IniFile);

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top