emacs-devel
[Top][All Lists]
Advanced

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

New macro with-demoted-errors


From: Stefan Monnier
Subject: New macro with-demoted-errors
Date: Sat, 07 Jul 2007 02:07:13 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

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 via email to

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