Export (0) Print
Expand All

Logic Error Catching 

This topic applies to:

Visual Studio Edition

Visual Basic

C#

C++

J#

Express

No

No

Native

No

Standard

No

No

Native

No

Pro/Team

No

No

Native

No

You can use assertion statements to catch logic errors. You can set an assertion on a condition that must be true according to the logic of your program. The assertion has no effect unless a logic error occurs.

For example, suppose you are simulating gas molecules in a container, and the variable numMols represents the total number of molecules. This number cannot be less than zero, so you might include an MFC assertion statement like this:

ASSERT(numMols >= 0);

Or you might include a CRT assertion like this:

_ASSERT(numMols >= 0);

These statements do nothing if your program is operating correctly. If a logic error causes numMols to be less than zero, however, the assertion halts the execution of your program and displays the Assertion Failed Dialog Box.

See Also

Community Additions

ADD
Show:
© 2015 Microsoft