Assert
Summary
Use the Assert
function to throw an error when a boolean expression returns false.
Syntax
Assert(Condition=< boolean expression> [,Message=<string>]) |
Return Type
The function returns the integer “0” if the Condition
input parameter successfully evaluates to true. Otherwise, the function throws an error.
Details
In some cases, a developer may want to force Connect to raise an error if some boolean expression evaluates to false. If used within a pipeline step, Assert
can cause the pipeline invocation to ungracefully halt execution when the Condition
expression evaluates to false
.
Consider using the OnConditionFalse
checks available to pipeline members to more gracefully handle business logic checks within a pipeline. Consider using a pipeline’s ContinueOnError
and OnError
parameters when using Assert. Refer to ALTER PIPELINE.
The ThrowException
function can also force Connect to throw errors. It is useful when the boolean checks occur outside of the function call, e.g. within a CASE
statement or IF-THEN-ELSE
conditional expression.
Although the Message
parameter is optional, Xactly recommends explicitly setting an error message that make sense for your particular use case. Otherwise, Connect will return a generic message stating, “Condition was false”. The error code number returned by Assert is always “37000”; only the error message string is customizable.
Examples
eval Assert(Condition=(‘cat’=’dog’), Message=’Custom Error Message: Hey! A cat is not a dog.’);
eval Assert(Condition=(‘dog’=’dog’), Message=’Custom Error Message: Hey! A cat is not a dog.’);
/* The following example uses a variable instead of placing the expression in the Condition
parameter. */
set v_file_check = Exists(FilePath=’/tmp/bogus_file.csv’);
eval Assert(Condition=(:v_file_check), Message=’bogus_file.csv was not found.’);