all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* New macro with-demoted-errors
@ 2007-07-07  6:07 Stefan Monnier
  2007-07-07 20:47 ` Richard Stallman
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2007-07-07  6:07 UTC (permalink / raw)
  To: emacs-devel


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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-07-08 14:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-07  6:07 New macro with-demoted-errors Stefan Monnier
2007-07-07 20:47 ` Richard Stallman
2007-07-08 14:08   ` Stefan Monnier

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.