all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Attaching context info to an error
Date: Thu, 28 Dec 2023 07:57:16 +0100	[thread overview]
Message-ID: <m2sf3mbyr7.fsf@Pro.fritz.box> (raw)
In-Reply-To: <jwva5q2b5bq.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Fri, 22 Dec 2023 10:58:57 -0500")

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>> The question is: where should we put this "context" info.
>>>
>>> One possibility is to do something like the following:
>>>
>>>     (defun load (file ...)
>>>       (handler-bind ((error (lambda (err)
>>>                               (signal 'error-during-load
>>>                                       (cons file err)))))
>>>         ...))
>>
>> I'm just guessing - so the argument ERR of the handler function is not a
>> `condition' object of some kind, in the CL sense? What is it?
>
> No, it's the same kind of objects as are bound to `err` in
> (condition-case err ...), i.e. a cons of (ERROR-NAME . ERROR-DATA).
>
> I don't think it makes sense to have different kinds of objects for
> `handler-bind` and for `condition-case`.

WRT to "collecting dynamic context info". I don't know if the following
is useful, it depends on what the context info is, but maybe it can
serve as an inspiration?

I was reading CMUCL code a bit today. CMUCL (and SBCL) do something 
like the below for handler-bind (and analogously for restart-bind):

  (defvar *handler-clusters* nil)

  (defmacro handler-bind (bindings &body forms)
    "(HANDLER-BIND ( {(type handler)}* )  body)
     Executes body in a dynamic context where the given handler bindings are
     in effect.  Each handler must take the condition being signalled as an
     argument.  The bindings are searched first to last in the event of a
     signalled condition."
    (unless (every #'(lambda (x) (and (listp x) (= (length x) 2))) bindings)
      (simple-program-error (intl:gettext "Ill-formed handler bindings.")))
    `(let ((*handler-clusters*
            (cons (list ,@(mapcar #'(lambda (x) `(cons ',(car x) ,(cadr x)))
                                  bindings))
                  *handler-clusters*)))
       (multiple-value-prog1
        (progn ,@forms)
        ;; Wait for any float exceptions
        #+x87 (float-wait))))

Each handler-bind is associated with a binding of *handler-clusters*,
which contains two things: the handlers of the handler-bind, and a link
to the next such binding up the stack. (This chain is used to find
handlers etc.).

Maybe one could use such a construct in Emacs to additionally associate
context with dynamic occurrances of handler-bind?



  reply	other threads:[~2023-12-28  6:57 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-21 22:30 Attaching context info to an error Stefan Monnier
2023-12-22  6:50 ` Gerd Möllmann
2023-12-22  8:37   ` Gerd Möllmann
2023-12-22 15:58   ` Stefan Monnier
2023-12-28  6:57     ` Gerd Möllmann [this message]
2023-12-22 20:56 ` Jens Schmidt
2023-12-22 22:37   ` Stefan Monnier
2023-12-23  3:02 ` João Távora
2023-12-23  3:28   ` João Távora
2023-12-26 20:12     ` Stefan Monnier
2023-12-26 20:47   ` Stefan Monnier
2023-12-26 22:43     ` João Távora
2023-12-27  6:50       ` Gerd Möllmann
2023-12-27 10:29         ` João Távora
2023-12-27 10:35           ` Gerd Möllmann
2023-12-27 17:50       ` Stefan Monnier
2023-12-27 18:08         ` João Távora
2023-12-27 18:28           ` João Távora
2023-12-27 19:08           ` Stefan Monnier
2023-12-27 19:27             ` João Távora
2023-12-27 20:27               ` Stefan Monnier
2023-12-27 23:08                 ` João Távora
2023-12-28  7:05                   ` Stefan Monnier
2023-12-28 14:12                     ` João Távora
2023-12-28 16:03                       ` Stefan Monnier
2023-12-28 17:15                         ` João Távora
2023-12-28 19:22                           ` Stefan Monnier
2023-12-28 23:53                             ` João Távora
2023-12-29  2:54                               ` Stefan Monnier
2023-12-29  3:43                                 ` João Távora
2023-12-29 16:54                                   ` Stefan Monnier
2023-12-29 17:29                                     ` João Távora
2023-12-29 17:39                                       ` João Távora
2023-12-30  4:29                                       ` Stefan Monnier
2023-12-30 16:45                                         ` João Távora
2023-12-29 17:19                                   ` Alan Mackenzie
2023-12-29 17:24                                     ` João Távora
2023-12-29 17:43                                       ` Alan Mackenzie
2023-12-29 17:54                                         ` João Távora
2023-12-29 18:08                                           ` Alan Mackenzie
2023-12-29 18:45                                             ` João Távora
2023-12-29 18:35                                         ` Stefan Monnier
2023-12-29 18:48                                           ` João Távora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2sf3mbyr7.fsf@Pro.fritz.box \
    --to=gerd.moellmann@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.