assert

Examples


The assert statement provides a mechanism for verifying the state of computation at a given point in a script.

Syntax

assert boolean_expression {, message}

Parameters

boolean_expression – An expression that you claim to be true when the assert statement is executed.

message – An optional string containing a message to include in the dialog displayed when the assertion fails.

Comments

An assertion is a claim about the state of computation at the time the assertion is evaluated. Assertions are always written as statements the programmer believes to be true. You can make your code self-testing by adding assertions. An assertion that fails indicates a potential problem in the script.

When an assert statement is encountered, its boolean expression (the assertion) is evaluated. If the expression is true, the script will continue. If the expression is false, a dialog box like the one shown in the following illustration will be displayed.

[spacer]

You can choose to abort the script, ignore the assertion or start the script debugger and examine the script where the assertion failed.

The assert statement is a development and testing tool. The dialog box indicating an assertion failed should not be displayed to the users of your application. By default, the runtime engine will not display the dialog box, even though an assertion failed. To allow testing with the runtime engine, add the RuntimeAsserts=TRUE setting to the defaults file. This forces the runtime engine to display the dialog box for any assertions that fail.

Since assertion dialogs should not be seen by users, and some overhead is involved in evaluating them, we recommend that you don’t compile assert statements for the final version of your product. To prevent assert statements from being compiled, don’t compile your application with debug information.


Documentation Feedback