-
Notifications
You must be signed in to change notification settings - Fork 2
guard
TurtleKitty edited this page May 11, 2019
·
2 revisions
This operator places a new handler on the error continuation. If an error is thrown, this handler will be called with an error argument and a retry continuation. If the handler returns a value, this becomes the value of the (guard ...) form. If the handler calls the retry continuation with a new value, the computation that threw the error is retried. If the handler throws an error itself, it goes to the next handler up on the error continuation.
(proc fun-handler (err kontinue)
(if (= err 'resume)
(kontinue 42)
(if (= err 'default)
69
(fail 'uh-oh))))
; no error
(+ 1
(guard
fun-handler
(+ 2 3)))
; 6
; default
(+ 1
(guard
fun-handler
(+ 2 (fail 'default))))
; 70
; continue
(+ 1
(guard
fun-handler
(+ 2 (fail 'resume))))
; 45
; abort
(+ 1
(guard
fun-handler
(+ 2 (fail 'crap))))
; (runtime-error uh-oh)
Vaquero programmers should beware of infinite loops when retrying errors.