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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to catch before Assertion Failure occurs...

Status
Not open for further replies.

drrep

Programmer
Mar 13, 2002
47
0
0
US
Well, I hope my topic made sense.

I have a program that opens files of some type and of a certain format (data is structured in a certain format) to be used in my program. These files contain simple text data.

Now, if I try to open a corrupt file, it will crash (Assertion Failure) because the data in it isn't in the right order and it must be for the program to read it open it correctly.

Any ideas on how I can catch that and maybe display the user of the program a message telling him/her how the file is corrupt and somehow avoid the user from having that terrible Assertion Failure message pop up?

Thanks in advance.
 
Well, you wrote the ASSERT statement (what else but your application can decide what is the "right order" of the data) yourself, right?

So, instead of
ASSERT(dataIsInRightOrder); // Or whatever

Either you
if (!dataIsInRightOrder)
{
// Handle situation
}

or you throw an exception and catch & handle the situation on a higher level.

Assertions are used to detect logical errors in the code, and not to check validity of indata.
 
>> avoid the user from having that terrible Assertion Failure message pop up

Only the debug version asserts...

#ifdef _DEBUG
#define ASSERT(f) if(f) AfxAssert...blahblahblah
#else
#define ASSERT(f)
#endif

 
Ah, apatterno, but a failed assertion indicates that something is wrong and should be fixed not just hidden with release build (and you could also have some kind of assertion management in release builds if you'd wish).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top