assertfail

assertfail, function

def pure assertfail(err: text): unit

Raises a runtime error with message err when executed. This function is only intended to be called inside a user-defined function body.

Examples

def pure nonNegativeSqrt(x: number) with
  if x < 0
    _ = assertfail("Expected non-negative x, got \{x}.")
  return sqrt(x)

show scalar "" with nonNegativeSqrt(9)

Output:

Result
3

Errors

Calling assertfail always raises a runtime error with the provided message.

Remarks

The return value of assertfail is not significant; assign it to the discard variable _.

User Contributed Notes
0 notes + add a note