Skip to main content

Panic.recover

Panic.recoverexpected_typesaction

Documentation

Executes the provided action and converts a possible panic matching any of the provided types into a dataflow Error. If action executes successfully, the result of Panic.recover is the result of that action. Otherwise, if it panicked with a type matching one of the expected error types, that panic is returned as a dataflow error. Unexpected panics are passed through as-is. it is the panic that was thrown after conversion to a dataflow error.

Arguments

  • expected_types: The types of expected panics which should be recovered. This can either be a Vector of types or a single type.
  • action: The code to execute that potentially panics.

Examples

Converting an expected panic to a dataflow error.

      Panic.recover Illegal_Argument (Panic.throw (Illegal_Argument.Error "Oh!" Nothing))

Converting one of many expected panic types to a dataflow error.

      Panic.recover [Illegal_Argument, Illegal_State] (Panic.throw (Illegal_Argument.Error "Oh!" Nothing))