Error Handling

Handle Every Error

If a function is capable of generating an error it should return its value in an unsafe(a) = Failure(exn) | Success(a) variant that captures either the value or the error.

To avoid having to handle the error, you can use the assertion operator to unwrap the value and force the encapsulating function to return an unsafe value.

fun unsafeFun -> raise(err);

fun alsoUnsafeFun -> {
  let x = unsafeFun()! + 10;
  
  x;
}

In this way we ensure that all errors are handled. If the main function exposed by the program is unsafe, the compilation will fail with an error.

Last updated