try
This function is used by Ignition's Expression language.
Descriptionβ
This expression is used to suppress errors caused by other expressions. The first expression will be evaluated, and if it executes successfully, its value will be used. However, if an error occurs while evaluating the expression, the value of the failover parameter will be used. When the failover is returned, its data quality will be applied.
Syntaxβ
try(expression, failover)
Parametersβ
| Type | Parameter | Description |
|---|---|---|
| Object | expression | An expression that can evaluate to any supported data type. |
| Object | failover | The value to return if an error occurs while evaluating expression. |
Returnsβ
Object - The result of the evaluated expression, or the failover value if an error occurs.
Examplesβ
Code Snippet
try(toInteger("boom"), -1) // returns -1 with a quality code of 192 (good)
Code Snippet
// fetch an integer value from the first row of a table. Return -1 if there are no rows
try({Root Container.Power Table.data}[0, 'Integer Column'], -1)