Static copy
Copied from docs/guides/errors-null-void.md in https://github.com/poppy-team/ori-lang (MIT). Pinned to revision 42e1817227fbc96e8e4a4a85fac78b3fec0a0e0f, blob f729d2e9d568f384f5e0c5d5e20ff1bb4ef8b532. The source repository remains canonical; this copy is refreshed through a sync pull request, not live.
Pedagogical guide (surface S3 + inference B / workspace 0.3.8-dev). Portuguese: errors-null-void.pt-BR.md
Normative: 09-errors, 04-types
| Concept | Role | When |
|---|---|---|
void | No useful return | Side-effect functions |
optional[T] | Value may be absent | Lookup, EOF — absence is not failure |
result[T, E] | Success or failure with reason | I/O, validation |
check | Runtime precondition | Invariants |
Ori has no null. Use none or err(...).
void module app.main
import ori.io as io
greet() -> void
io.println("hello")
end
main()
greet()
endoptional[T] module app.main
find_user(id: int) -> optional[string]
if id == 0
return none
end
return some("alice")
end
main()
match find_user(1)
case some(name):
-- use name
case none:
end
endif some(x) = expr or match.try on optional propagates none.? was removed in S3.result[T, E] module app.main
import ori.fs as fs
read_config(path: string) -> result[string, string]
return fs.read_text(path)
endok(value) / err(reason) (not success / error).match or try expr.check divide(a: int, b: int) -> int
check b != 0, "division by zero"
return a / b
endFails the process on broken contracts; it is not a result.
| Situation | Use |
|---|---|
| Print only | -> void |
| “Not found”, not an error | optional[T] |
| Failure with message | result[T, string] |
| Must always be true | check |
ori explain name.undefined
ori doctorCatalog: 13-error-catalog.md.