Previous: exception-predicate, Up: Exception Handling [Contents][Index]
assert
The assert
statement allows you test if a condition is true,
if not, the program will raise an exception with code EC_assert
.
assert (condition) assert (condition, message)
The optional message will be part of the msg
field of
raised Exception
to explain the situation. If no message
is explicitly specified, msg
is set to the source code of the
expression evaluated as the assert condition.
assert (1 == 1); assert (0 == 0, "Zero is equal to zero");
assert
is useful for writing unit tests.