pragma Assert

Name

Assert -- 

Synopsis

pragma Assert (
  boolean_EXPRESSION
  [, static_string_EXPRESSION])

Description

The effect of this pragma depends on whether the corresponding command line switch is set to activate assertions. If assertions are disabled, the pragma has no effect. If assertions are enabled, then the semantics of the pragma is exactly equivalent to:

if not Boolean_EXPRESSION then
   System.Assertions.Raise_Assert_Failure (string_EXPRESSION);
end if;

The effect of the call is to raise System.Assertions.Assert_Failure. The string argument, if given, is the message associated with the exception occurrence. If no second argument is given, the default message is "file:nnn", where file is the name of the source file containing the assert, and nnn is the line number of the assert. A pragma is not a statement, so if a statement sequence contains nothing but a pragma assert, then a null statement is required in addition, as in:

...
if J > 3 then
   pragma Assert (K > 3, "Bad value for K");
   null;
end if;

If the boolean expression has side effects, these side effects will turn on and off with the setting of the assertions mode, resulting in assertions that have an effect on the program. You should generally avoid side effects in the expression of this pragma.