Hi,
"John Trammell" <[EMAIL PROTECTED]> writes:
> (define (cleanup)
> (simple-format #t "has-plan: ~a~%" has-plan)
> (simple-format #t "1..~a~%" index))
>
> (catch 'quit
> (lambda () (exit 1))
> (lambda (key . args)
> (begin (format #t "in handler~%")
> (format #t "key:~a args:~a~%" key args)
> (cleanup))))
>
> (set! has-plan #t)
> (format #t "fiddle dee dee~%")
No, you would want to enclose the body of your code in `catch', i.e.,
(catch 'quit
(lambda ()
;; your code
...)
(lambda (key . args)
...))
Anyway, this isn't good, because if your code doesn't call `exit', then
the `quit' exception is never raised.
`dynamic-wind' provides a better solution, since the "handler" is called
whenever the dynamic extent of the body is left:
(dynamic-wind
(lambda ()
;; nothing to do here
#t)
(lambda ()
;; the code body
;; ...
)
(lambda ()
;; the "exit guard" or "handler", which gets called whenever the
;; body's extent is left, including via an `exit' call
))
If your code uses C code that may exit in other ways (e.g., C code that
calls `exit(3)' or similar), then you need an `atexit' similar to what
Neil described.
Thanks,
Ludovic.