The catcherror( function evaluates an expression, but suppresses any error generated by that expression.
Parameters
This function has two parameters:value – value to return if the expression generates an error.
primary – the expression being evaluated.
Description
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:
fileload(cityName+".info")
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:
catcherror("",fileload(cityName+".info"))
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 fileload( function and replace the error with empty text.
catcherror("",upper(fileload(cityName+".info")))
upper(catcherror("",fileload(cityName+".info")))
Note: This function cannot catch syntax errors, only evaluation errors. So this formula:
catcherror("",x*)
will still cause an error, because
x*
is not a valid formula.
See Also
History
Version | Status | Notes |
10.0 | New | New in this version. |