On 8/17/2017 11:47 AM, David Storrs wrote:
On Thu, Aug 17, 2017 at 2:44 AM, Sam Waxman <samwax...@gmail.com
<mailto:samwax...@gmail.com>> wrote:
Hey all,
One of the things that confuses me most in Racket is good error
handling, and the continuations that are involved.
Is it possible to raise an error, have the user see it, but then
still go on running the code? I can currently catch an error,
display it as a string/other formats and then keep running my
code, but is it possible to have the error be raised and then the
continuation it goes to afterwards continue evaluating the code?
Thanks
The exception object is:
(struct exn
<https://docs.racket-lang.org/reference/exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn%29%29>(messagecontinuation-marks)
#:extra-constructor-namemake-exn
<https://docs.racket-lang.org/reference/exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._make-exn%29%29>#:transparent)
I think the 'continuation-marks' field contains the continuations from
where you were when the exception was thrown, so you should be able to
jump back there. Does that help?
AFAIK, continuation-marks aren't set on every form, so I don't think it
would help for Sam's purpose.
I can envision a complicated way to do it that would at least work for
most imperative code [functional would be a PITA] ... but it would need
to be implemented as a syntax macro to be effective. General idea is:
(define (execute-with-errors . forms)
(let [
(cont (lambda (x) x))
]
(with-handlers
[
(exn:fail?
(lambda (e)
(eprintf "~s" (exn-message e))
(cont)))
]
(for [(f (in-list forms))]
(let/ec cc
(set! cont cc)
(f)))
)))
The devil would be in the details: What to do with non-function
objects? What to do with functional expression code? Etc.
YMMV,
George
--
You received this message because you are subscribed to the Google Groups "Racket
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.