unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Nic Ferrier <nferrier@ferrier.me.uk>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: emacs-devel@gnu.org
Subject: Re: capturing backtraces
Date: Mon, 25 Aug 2014 21:13:44 +0100	[thread overview]
Message-ID: <87sikkxr7r.fsf@ferrier.me.uk> (raw)
In-Reply-To: <87vbpgy1og.fsf@ferrier.me.uk> (Nic Ferrier's message of "Mon, 25 Aug 2014 17:27:43 +0100")

Oh well.

I wrote this:

 (defmacro try (form &rest body)
   "Try FORM and eval BODY if it fails.

 Within BODY `backtrace' will return the backtrace including the
 stack which caused the problem.  This can be used for actually
 debugging the problem."
   (declare (indent 1))
   (let ((ret-var (make-symbol "ret-var")))
     `(let* (,ret-var
             (debug-on-error t)
             (debugger
              (lambda (&rest args)
                (setq ,ret-var (progn ,@body)))))
        (condition-case err
            (setq ,ret-var (progn ,form))
          ((debug error)))
        ,ret-var)))

To be used like this:

 (try
   (something-that-causes-an-error)
  (handle-the-error
     possibly-doing
     (with-output-to-string (backtrace))))

It's not perfect because the backtrace you get like that includes the
stuff after the debugger enters. It's slightly odd behaviour. If I
understand it correctly the debugger is entered directly from the
error. So the debugger appears to be a continuance (I don't mean a
Scheme continuation) of the stack which caused the error.

I wonder if I can repeatedly do this, if errors need to be properly
"quit" somehow.

I'll give it a go in marmalade, that's quite a stressful environment for
this sort of thing.


Nic



      reply	other threads:[~2014-08-25 20:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-24 20:43 capturing backtraces Nic Ferrier
2014-08-24 21:14 ` Nic Ferrier
2014-08-25  2:43   ` Samuel Bronson
2014-08-25 14:57   ` Stefan Monnier
2014-08-25 16:27     ` Nic Ferrier
2014-08-25 20:13       ` Nic Ferrier [this message]

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87sikkxr7r.fsf@ferrier.me.uk \
    --to=nferrier@ferrier.me.uk \
    --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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).