Chapter 9

Modules and Errors

Organize code, propagate structured errors, and unwind resources reliably.

Pure HHY modules

example.hhy
import { add } from "./math.hhy"

add(20, 22) |> print

V1.0 supports relative imports, named imports, aliases, exports, module caching, and cycle detection. Remote imports and third-party package installation are not included.

Structured errors

example.hhy
try {
    read_text(path("config.json"))
        |> parse_json
        |> print
} catch err {
    print_error(err)
    exit(1)
}

try/catch handles eager errors; on_error can recover lazy Flow errors. Every failure travels through one Error stage and resources unwind when scope exits.