emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Attaching context info to an error


From: Stefan Monnier
Subject: Re: Attaching context info to an error
Date: Tue, 26 Dec 2023 15:47:23 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

>> I'm playing with `handler-bind` and trying to see how we could make use
>> of such a functionality in Emacs.
> *loud cheers*
[...]
> Amongst the killer weaponry this gives us is a restart system,
> finally.

I fail to see the connection, to be honest.

> (defun pm/call-with-retry-restart (outer inner msg fn)
>   (catch outer
>     (let ((saved-restarts pm/restarts))
>       (unwind-protect
>           (while t
>             (catch inner
>               (handler-bind ((error (lambda (_e)
>                                       (push
>                                        (list 'retry msg
>                                              (lambda ()
>                                                (throw inner nil)))
>                                        pm/restarts))))
>                 (throw outer (funcall fn)))))
>         (setq pm/restarts saved-restarts)))))

Rather than `(let ((saved-restarts pm/restarts))` why not `(let
((pm/restarts pm/restarts))` so you don't need the `setq` in the
`unwind-protect`?

And why `handler-bind`.  IOW, why wait until the error happens before
pushing the retry onto the list?  Why not just:

    (defun pm/call-with-retry-restart (outer inner msg fn)
      (catch outer
        (let ((pm/restarts
               (cons (list 'retry msg
                           (lambda () (throw inner nil))))))
          (while t
            (catch inner
              (throw outer (funcall fn)))))))


-- Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]