Operators > Programming Operators > Try/On Error Operator
Try/On Error Operator
Evaluates x. If x produces an error, the operator evaluates and returns y. Otherwise it returns x. The try/on error operator is a distinct type of conditional operator, guiding execution only in the event of an error during calculation.
x, y are any valid expressions or sequence of expressions. For example, a local assignment, a function call, or a sequence of programming steps is allowed.
Here, try/on error is used to avoid dividing by zero. When x is 2, the program evaluates as ∞, rather than returning a singularity.
The on error placeholder must contain an expression that always evaluates properly. You can use try/on error to return a variable for debugging purposes, perform an alternate calculation, or exit the program and return a custom error message.
Additional Information
You can type the word try and then press Ctrl+J to convert the word to a programming operator with all its placeholders.
Was this helpful?