Difference between revisions of "$Assertions"

From Lazarus wiki
Jump to navigationJump to search
m (Trev moved page sAssertions to $Assertions: Dollar signs in page titles are ok)
(add →‎see also: to PG)
 
Line 29: Line 29:
  
 
If the ''BooleanExpression'' is false, an optional error message (AssertMessage) is output with the file name, the line number and the address and the program aborts with Runtime error 227. If ''BooleanExpression'' is true, program execution continues normally. If assertions are not enabled at compile time, the Assert routine does nothing, and no code is generated for the Assert call.
 
If the ''BooleanExpression'' is false, an optional error message (AssertMessage) is output with the file name, the line number and the address and the program aborts with Runtime error 227. If ''BooleanExpression'' is true, program execution continues normally. If assertions are not enabled at compile time, the Assert routine does nothing, and no code is generated for the Assert call.
 +
 +
== see also ==
 +
* [https://freepascal.org/docs-html/current/prog/progsu5.html <syntaxhighlight lang="text" inline>$C</syntaxhighlight> or <syntaxhighlight lang="text" inline>$ASSERTIONS</syntaxhighlight>: Assertion support] in the Programmer’s Guide

Latest revision as of 14:32, 11 February 2021

Deutsch (de) English (en)


Back to local compiler directives.


The local compiler directive $C or $ASSERTIONS:

  • is used for error detection;
  • determines whether an expression is compiled or not. If the directive is active, then the Assert expression is compiled.

Examples:

...
{$ASSERTIONS ON} 
...
Assert(BooleanExpression, AssertMessage);
...
...
{$C ON} 
...
Assert(BooleanExpression);
...

If the BooleanExpression is false, an optional error message (AssertMessage) is output with the file name, the line number and the address and the program aborts with Runtime error 227. If BooleanExpression is true, program execution continues normally. If assertions are not enabled at compile time, the Assert routine does nothing, and no code is generated for the Assert call.

see also