The catcherror( function evaluates an expression, but suppresses any error generated by that expression.
This function has two parameters:
value – value to return if the expression generates an error.
primary – the expression being evaluated.
This function allows you to suppress an error message “after the fact.” This function is really handy any time you would prefer a default value (usually text) instead of an error message.
For example, suppose you had information about various cities in different files – perhaps you have files for Denver, Chicago, Miami, Seattle, etc. You could allow the user to type the city name into a field or variable named, cityName, and then in a Text Display object you could display this information with this formula:
The only problem is, what if the user types in a city name for which you have no pre-defined file? In that case, the Text Display object will display a possibly confusing message about a file that doesn’t exist. The catcherror( function can fix this. Here is a revised formula that displays Unknown city name instead of an error message:
catcherror("Unknown city name",fileload(cityName+".info"))
Or you could simply set up the Text Display object to display nothing if there is an error:
The catcherror( function will catch the error even if it is nested deep within the formula. The following two formulas will both catch any error in the grabfilevariable( function and replace the error with empty text.
Note: This function cannot catch syntax errors, only evaluation errors. So this formula:
will still cause an error, because
is not a valid formula.
|10.0||New||New in this version.|