* dgnushack.el (fboundp): Define `with-demoted-errors' for Emacsen that doesn't...
authorLars Magne Ingebrigtsen <larsi@stories.gnus.org>
Mon, 21 Nov 2011 20:10:51 +0000 (21:10 +0100)
committerLars Magne Ingebrigtsen <larsi@stories.gnus.org>
Mon, 21 Nov 2011 20:10:51 +0000 (21:10 +0100)
lisp/ChangeLog
lisp/dgnushack.el

index e18789e..8a9619d 100644 (file)
@@ -1,5 +1,8 @@
 2011-11-21  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
+       * dgnushack.el (fboundp): Define `with-demoted-errors' for Emacsen that
+       doesn't have it.
+
        * mm-view.el (mm-display-inline-fontify): Make the font-lock variables
        buffer-local instead of binding them to avoid warnings.  Also demote
        errors (bug#10063).
index e3110d7..987bb28 100644 (file)
@@ -549,4 +549,16 @@ or remove them using `make remove-installed-shadows'.\n\n"))))))))
              (error (princ "failed\n")))))
        (setq path (cdr path))))))
 
+(unless (fboundp 'with-demoted-errors)
+  (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 signaled."
+    (declare (debug t) (indent 0))
+    (let ((err (make-symbol "err")))
+      `(condition-case-no-debug ,err
+          (progn ,@body)
+        (error (message "Error: %S" ,err) nil)))))
+
 ;;; dgnushack.el ends here