unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: New macro with-demoted-errors
Date: Sat, 07 Jul 2007 02:07:13 -0400	[thread overview]
Message-ID: <jwv7ipcpx7p.fsf-monnier+emacs@gnu.org> (raw)


I often want to use CL's `ignore-errors' but am annoyed regularly that its
use tends to hide bugs and make them harder to track down.  

So I sugest we introduce a new macro with-demoted-errors which does the same
thing except that errors are reported (via message) to the user rather than
being silently ignored.  Also errors are not ignored if debug-on-error is
set, in the hope to make debugging easier.

The patch below includes a sample use of it in VC where it makes sure that
any error in a vc-BACKEND-registered function will not prevent the user from
visiting a file.


        Stefan


--- orig/lisp/subr.el
+++ mod/lisp/subr.el
@@ -2552,6 +2552,20 @@
 	   (or (input-pending-p)
 	       ,@body))))))
 
+(defmacro with-demoted-errors (&rest body)
+  "Run BODY and demote any errors to simple messages.
+If `debug-on-error' is non-nil, run BODY without catching its errors.
+This is to be used around code which is not expected to signal an error
+but which should be robust in the unexpected case that an error is signalled."
+  (declare (debug t) (indent 0))
+  (let ((err (make-symbol "err")))
+    `(lexical-let ((f (lambda () ,@body)))
+       (if debug-on-error
+           (funcall f)
+         (condition-case ,err
+             (funcall f)
+           (error (message "Error: %s" ,err) nil))))))
+
 (defmacro combine-after-change-calls (&rest body)
   "Execute BODY, but don't call the after-change functions till the end.
 If BODY makes changes in the buffer, they are recorded

--- orig/lisp/vc-hooks.el
+++ mod/lisp/vc-hooks.el
@@ -834,7 +834,7 @@
   (when buffer-file-name
     (vc-file-clearprops buffer-file-name)
     (cond
-     ((vc-backend buffer-file-name)
+     ((with-demoted-errors (vc-backend buffer-file-name))
       ;; Look for pending-partial-checkin file and deal with it if found.
       (vc-after-partial-checkin buffer-file-name)
       ;; Compute the state and put it in the modeline.

             reply	other threads:[~2007-07-07  6:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-07  6:07 Stefan Monnier [this message]
2007-07-07 20:47 ` New macro with-demoted-errors Richard Stallman
2007-07-08 14:08   ` Stefan Monnier

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=jwv7ipcpx7p.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /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).