Std.Throw

import Std.Throw

Source


Types


Result

type Result t e =
    | Ok t
    | Err e

source


Effects


Throw

effect Throw t =
    throw: fn t -> Never

source


Functions


catch

catch (f: a can Throw e): Result a e

source


catch_or

catch_or (f: a can Throw e) (default: a): a

source


catch_or_else

catch_or_else (f: a can Throw e) (default: fn e [_] -> a): a

source


on_err

on_err (f: a can Throw e) (on_err: fn e [_] -> Unit): Unit

source


map_err

map_err (f: t can Throw e1) (f2: fn e1 [_] -> e2): t can Throw e2

Apply the given function to the thrown value and re-throw it

source


unwrap_err

unwrap_err (f: t can Throw e): e can Fail

Returns the error when thrown or fails if the operation finishes without throwing.

source


exit_on_throw

exit_on_throw (f: a can Throw t, e) {_: Display t e2}: a can Fs, e, e2

If an error is thrown when running f, print it to stderr and exit 1

source