emacs-devel
[Top][All Lists]
Advanced

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

Re: capturing backtraces


From: Nic Ferrier
Subject: Re: capturing backtraces
Date: Mon, 25 Aug 2014 21:13:44 +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 via email to

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