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

Errors as Values

Mint an error type and include it in a return union. The caller handles that alternative explicitly.

ParseError:type = type of error & [message:string]
parse = (text:string):>int64|ParseError => {
    let value = to_int(text)
    if value is? error { return ParseError["invalid integer"] }
    return value
}
let result = parse("42")
if result is? int64 { printl(result) }

Expected output:

42

Run the example from a file with dewy example.dewy. Its exact output is checked by the website build on the native release target.

Design boundary. The Errors as Values reference specifies the complete language rules. A passing example covers this program only. See generated coverage for related acceptance programs and unmeasured areas.