Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error Handling

Atlas77 standard style favors explicit result types.

Use optional for maybe-present values:

import "std/optional";

fun find_id(ok: bool) -> optional<int64> {
    if ok { return optional<int64>::of(1); }
    return optional<int64>::empty();
}

Use expected<T, E> for value-or-error outcomes:

import "std/expected";

fun parse(x: int64) -> expected<int64, string> {
    if x < 0 { return expected<int64, string>::unexpected("negative"); }
    return expected<int64, string>::expect(x);
}