assert
Sets an error if the given condition, s, is not satisfied. An optional input argument, errormessage may be used to customize the error displayed when assert fails.
Syntax
assert(s)
assert(s, errormessage)
Inputs
- s
- Condition to be satisfied.
- errormessage (optional)
- Message to pass to error handler if s is not met.
Examples
Assertion failure, without any special error handling:
y = 1;
x = 2 * y;
assert(x == y - 1)
Error: assert failed
Assertion failure, with custom error
message:
y = 1;
x = 2 * y;
assert(x == y, 'x and y are not equal')
Error: x and y are not equal