Skip to main content

Any.catch

catcherror_type handler

Group: Errors

Documentation

Executes the provided handler on an error, or returns the value unchanged.

Arguments

  • error_type: The type of error to handle. Defaults to Any to handle all errors.
  • handler: The function to call on this if it is an error value of a matching type. By default this is identity.

Examples

Catching an Illegal_Argument and returning its message.

      from Standard.Base import all

example_catch =
error = Error.throw (Illegal_Argument.Error "My message")
error.catch Illegal_Argument (err -> err.message)

Catching any dataflow error and turning it into a regular value.

      from Standard.Base import all

example_catch =
error = Error.throw 42
error.catch == 42