I think you want with-handler*? According to the docs:

with-handlers:

Before any predicate or handler procedure is invoked, the continuation of
the entire with-handlers
<https://docs.racket-lang.org/reference/exns.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._with-handlers%29%29>
expression is restored, but also parameterize-break
<https://docs.racket-lang.org/reference/breakhandler.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._parameterize-break%29%29>ed
to disable breaks. Thus, breaks are disabled by default during the
predicate and handler procedures (see Breaks
<https://docs.racket-lang.org/reference/breakhandler.html>), and the
exception handler is the one from the continuation of the with-handlers
<https://docs.racket-lang.org/reference/exns.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._with-handlers%29%29>
expression.

with-handler*

Like with-handlers
<https://docs.racket-lang.org/reference/exns.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._with-handlers%29%29>,
but if a handler-expr procedure is called, breaks are not explicitly
disabled, and the handler call is in tail position with respect to the
with-handlers*
<https://docs.racket-lang.org/reference/exns.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._with-handlers%2A%29%29>
form.

On Thu, Oct 7, 2021 at 5:36 PM 'William J. Bowman' via Racket Users <
[email protected]> wrote:

> I have a little model of a server below. The server handles all
> exceptions, and restarts itself after some errors. It also handles break?,
> to actually exit when requested.
>
> While this server is running, if I press Ctrl+C before `(error 'foo)` is
> handled, the server exits correctly with 120. However, if I press Ctrl+C
> after `(error 'foo)` is handled, the `exn:break?` handler is never called,
> the server no longer responds to `Ctrl+C`, and (in this example) it
> eventually exits with status `1`.
>
> I cannot figure out why. As far as I can tell, this should always handle
> `Ctrl+C` by exiting with 120.
>
> > #lang racket/base
> >
> > (let loop ([n 0])
> >   (with-handlers ([exn:break? (lambda _ (exit 120))]
> >                   [void
> >                    (lambda (exn)
> >                      (printf "handled error: ~a~n" (exn-message exn))
> >                      (loop (add1 n)))])
> >     (displayln n)
> >     (sleep 1)
> >     (cond
> >       [(zero? n) (error 'foo)]
> >       [(= n 5) (exit 1)])
> >     (loop (add1 n))))
>
> --
> William J. Bowman
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/YV%2BSWNpldfOB5tA3%40williamjbowman.com
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CADcuegvKwRkOuC_3nQ4UqWFVK2kac1nCgucYuFz%2BD%2BRJnD0kNg%40mail.gmail.com.

Reply via email to