safe_mode

Guarantee execution of a line

Definition

any safe_mode(any input, &expression)

Tries to apply &expression to input. In case an error occurs, doesn't interrupt the execution of the program, but returns null instead and raises the error as a warning instead. If there is no error, returns the result of applying &expression to input.

Parameters

any input

Data to apply &expression to.

expression &expression

Expression to apply on data.

Returns

any

If applying &expression to input yields no error, returns the result. Otherwise, suppresses the error and returns null.

Examples

{
  a: safe_mode(`[0, 1]`, divide(@[0], @[1])),
  b: safe_mode(`[0, 1]`, divide(@[1], @[0]))
}
{
  "a": 0,
  "b": null    // Only a warning is raised
}