AssertInArray
Back to ListDescription: Function to assert that a given value is contained in a supplied array.
FileMaker Prototype:
Set Variable [$res; ACF_Run("AssertInArray"; string_value; arraystring_arr; string_message)]
Category: UTILITY
Dependencies
- find_in_array: Find an item in an ACF array
Function source:
function AssertInArray ( string value, array string arr, string message )
int x = find_in_array (arr, value);
if (x<0) then
throw (message);
end if
return true;
end
The AssertInArray Function ensures that a given value is contained in a supplied array. If not, an exception is thrown with the message in the third parameter. It is usually used by other ACF functions and not called directly from FileMaker.
Example
array string VatCodes = {"High", "Medium", "Low", "zero-rate"};
bool b1 = AssertInArray ( "Hi", VatCodes, "Invalid VAT code detected. ");
In this example, we will have an exception that means that the ACF function is aborted, returning this message to FileMaker. If there is a TRY-CATCH block in place, this will be triggered instead to handle the error.
Example output
This is what is returned to FileMaker if this exception occurs.
ERROR - Exception: Thrown in: assertinarray:Invalid VAT code detected.
(pc:502)
Note: The (pc:502) refers to the program counter at the location where the exception occurred. Compiling the source with a debug level greater than 0 will produce an assembly listing of the code with source lines and addresses. This will allow you to pinpoint the exact location where the exception was thrown.
