catcherror(
catcherror(
VALUE
,
PRIMARY
)

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 grabfilevariable( 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

- defaulttext( -- returns a text value, or returns a default value if the text value is empty ("").
- Error Handling -- Techniques for trapping runtime errors instead of letting them abort the program.
- Error Wizard -- Advanced dialog for displaying program errors.
- error( -- returns an error with the specified message.
- errortext( -- evaluates an expression, but returns only the error message generated (if any).
- executecatcherrors -- is the same as the execute statement, except for the fact that if an error occurs while running, it can be trapped by an if error statement immediately following the executecatcherrors statement.
- info("error") -- returns the most recent error message.
- info("errorparameter") -- returns the parameter that caused a runtime error.
- info("errorstack") -- returns the contents of the procedure stack after an error.
- info("errorstatement") -- returns the name of the statement that Panorama was trying to run at the time an error occurred.
- onerror -- can be used to catch all errors that are not trapped by if error or try statements.
- onfailedresume -- is used to setup a semi-graceful recovery if a resume statement fails because there was no pause statement.
- returnerror -- passes an error back to the current subroutines calling procedure.
- seterror -- changes the error message returned by info("error").
- throwerror -- causes an immediate error.

History

Version | Status | Notes
10.0 | New | New in this version.