Scripting reference · Nerdamer Language

iferror

Returns a fallback value when an expression throws an error.

If expression works, its value is returned and fallback isn't evaluated.

Scripting

iferror(expression, fallback)

Write it in a script: nerdamer('iferror(5,0/0)'), or in the Playground.

Parameters

expression
The expression to try.
fallback
The value to use if it throws an error.

Examples

The expression works, so the fallback never runs.

iferror(5,0/0)
// → 5
Open in Playground

0/0 throws, so the fallback is used.

iferror(0/0,7)
// → 7
Open in Playground

Fallbacks can be nested.

iferror(1/0, iferror(2/0, 9))
// → 9
Open in Playground

Good to know

  • return, break and continue pass through iferror: they aren't treated as errors.

← Back to Nerdamer Scripting