Click or drag to resize
Catch

[This is preliminary documentation and is subject to change.]

The TOPICA Basic function Catch is used to catch exceptions encountered during evaluation of expressions.

In most cases the message associated with the exception is displayed in the user interface.

An exception is a symptom of a configuration error. There might be situations where the Role Configurator does not want to have such messages displayed to the Role End User, e.g. to quietly return a default value in case of exception.

The Catch function is a mechanism that allows the configurator to catch any exception, and return a default value instead.

Syntax
Catch(ExpressionThatMightFail, DefaultValue)

Result type: Any - type of ExpressionThatMightFail or DefaultValue.

Parameters

Name

Type

Description

ExpressionThatMightFail

Any

The expression to be evaluated. If no exception is encountered during the evaluation, the evaluated value (for ExpressionThatMightFail) is return as the result of Catch.

DefaultValue

Any

If an exception is encountered during the evaluation of ExpressionThatMightFail), DefaultValue is returned as the value of Catch.

Example
Catch(1.0/3.0, "ERROR")

This expression will return the value 0.3333333333333333 (a floating-point number, e.g. type Double)

Catch(1.0/0.0, "ERROR")

This expression will return the value "ERROR" (type String).

Remarks

The proper approach is to AVOID errors (exceptions) during evaluation. Example: Accessing properties on null objects will throw an exception (in "strict" mode). For objects that may be null, test that the object is not null before accessing properties on that object.

Example 1;

If(IsNull(Record.UpdatedBy), "Record never updated", "Record last updated by: " + Record.UpdatedBy.Username)

Example 2:

Catch("Record last updated by; " + Record.UpdatedBy.Username, "Record never updated")

The above examples return the same value, but example 1 is the correct way to go.

Note Note

Use Catch only as a last resort. Exception handling causes a much bigger run-time overhead that checking to avoid the exception, so relying on exceptions will imply a performance penalty. Furthermore, when the configurated TOPICA Basic code generates exceptions, it is harder to debug the TOPICA framework. So avoiding exceptions in the configurated TOPICA Basic code makes life easier for Role Framework Developer.

See Also