![]() |
| ||||
Navigation |
Synopsis An executable assertion.
Syntax
Types
Description An assert statement may occur everywhere where a declaration is allowed. It has two forms:
An assert statement consists of a Boolean expression Exp1 and an optional string expression Exp2
that serves as a identifying message for this assertion.
When Exp1 evaluates to false , an AssertionFailed exception is thrown.
Examples
rascal>assert 1==2 : "is never true"; |stdin:///|(14,15,<1,14>,<1,29>): AssertionFailed("is never true") at ___SCREEN_INSTANCE___(|main://___SCREEN_INSTANCE___|) rascal>int div(int x, int y) { >>>>>>> assert y != 0 : "y must be non-zero"; >>>>>>> return x / y; >>>>>>>} int (int, int): int div(int, int); rascal>div(4,0); |stdin:///|(42,20,<2,18>,<2,38>): AssertionFailed("y must be non-zero") at div(|stdin:///|(6,1,<1,6>,<1,7>)) at ___SCREEN_INSTANCE___(|stdin:///|(0,9,<1,0>,<1,9>)) ![]() |