Category: Logical function
This function returns the result of expression2 if the result of expression1 is an error. Otherwise, it returns the result of expression1.
This function can be used as an error handler in cases where an expression could potentially return an error. In such a case, the return value from expression2 acts as a "safety net" so the process can continue.
Argument | Type | Description |
---|---|---|
expression1 | Expression | Any expression that could potentially result in an error. |
expression2 | Expression | Any expression. |
Return value type: Any (The data type of the return value of expression1 or expression2.)
If both expression1 and expression2 return errors, the error message from expression2 is returned.
iferror( 1/0, 'Inifity' ) //Returns 'Infinity'
iferror( 1+0, 'Infinity' ) //Returns 1
iferror( 1/0, sqrt('the') ) //Returns '#The argument must be a positive number' (the error from expression2)