-
Notifications
You must be signed in to change notification settings - Fork 0
Error handling
Joakim edited this page Oct 10, 2021
·
29 revisions
Exploration of error handling, inspired by vlang, using error recovery operator !?
.
-- function returning an error
get-user: (id: #number) -> #user! -- function typed as returning either a #user or an #error
db.get(table: 'user', id) ? error "User { id } not found"
-- returns an #error if db.get() returns #nothing
-- default value
user: get-user(7) !? default-user
-- propagate error (early return)
user: get-user(7) !? return error('Loading failed', [cause: _])
-- pattern matching of error
user: get-user(7) !? match _
#db-error(err) -> return err
_ -> default-user
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.)