-
Notifications
You must be signed in to change notification settings - Fork 0
Error handling
Joakim edited this page Nov 1, 2021
·
29 revisions
Exploration of error handling, inspired by vlang, using error recovery operator ?!
.
-- function possibly returning an error
get-user: (id: #number) -> #user | #error
db.get(table: 'user', id) ? Error "User { id } not found"
-- returns an #error if db.get() returns #none
-- ignore error, fallback to a default value
user: get-user(7) ?! default-user
-- propagate error, return early
user: get-user(7) ?!
return Error 'Loading failed'
-- even better, retain original error
user: get-user(7) ?! as cause
return Error('Loading failed', [cause])
This programming language only exists as a design. I'm unlikely to ever get the chance to write a compiler for it.
Feel free to steal any parts of it that you like. Ideas are better stolen than forgotten. (They're not my ideas anyway.)