* dgnushack.el (fboundp): Define `with-demoted-errors' for Emacsen that doesn't...
[gnus] / lisp / dgnushack.el
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