Cicode Programming Reference > Cicode Function Categories > Miscellaneous Functions Introduction > Assert

Assert

Verifies that the specified expression is TRUE. If then expression is FALSE, the current task will be halted. This is useful to help prevent the execution of code you do not want to run in the event an error has been detected.

This function can be used in a debug mode, where the FALSE assertion will be logged to the Kernel and SysLog.DAT, with the time, date, Cicode file name, and line number. Additionally the operator will be prompted with a dialog. The debug mode can be set by using the [Code]DebugMessage parameter or DebugMsgSet() function.

Note: If you have the "Citect will start debugger on hardware errors" option set in the Cicode Editor, the Debugger will start with the position before the Halt() instruction. You need to 'step over' this command if you want to continue debugging the function that called the Assert().

Syntax

Assert(bCondition)

bCondition:

The boolean expression. This expression needs to evaluate to TRUE (1) or FALSE (0).

Return Value

None. However, if the assertion tests as FALSE, error 347 is generated.

Related Functions

Halt, DebugMsg, DebugMsgSet, CodeTrace, TraceMsg, ErrLog

Example

INT
FUNCTION FileDisplayEx(STRING sFileName);
INT hFile;
hFile = FileOpen(sFileName, "r");
Assert(hFile <> -1);
...
FileClose(hFile);
RETURN 0;
END

See Also

Miscellaneous Functions