Assertions are a way of breaking out of code when there is an error or an unexpected input.

Some languages throw exceptions and some treat it as a break point.



Task

Show an assertion in your language by asserting that an integer variable is equal to 42.




 
/* PL/I does not have an assert function as such, */
/* but it is something that can be implemented in */
/* any of several ways.  A straight-forward way   */
/* raises a user-defined interrupt. */
 
on condition (assert_failure) snap
   put skip list ('Assert failure');
....
if a ^= b then signal condition(assert_failure);
 
/* Another way is to use the preprocessor, thus: */
%assert: procedure (a, b) returns (character);
   return ('if ' || a || '^=' || b ||
      ' then signal condition(assert_failure);');
%end assert;
%activate assert;
 
assert(a, 42);
 