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.




-- in a movie script
on assert (ok, message)
  if not ok then
    if not voidP(message) then _player.alert(message)
    abort -- exits from current call stack, i.e. also from the caller function
  end if
end
 
-- anywhere in the code
on test
  x = 42
  assert(x=42, "Assertion 'x=42' failed")
  put "this shows up"
  x = 23
  assert(x=42, "Assertion 'x=42' failed")
  put "this will never show up"
end