Function: with-demoted-errors
with-demoted-errors is a macro defined in subr.el.gz.
Signature
(with-demoted-errors FORMAT &rest BODY)
Documentation
Run BODY and demote any errors to simple messages.
FORMAT is a string passed to message to format any error message.
It should contain a single %-sequence; e.g., "Error: %S".
If debug-on-error is non-nil, run BODY without catching its errors.
This is to be used around code that is not expected to signal an error
but that should be robust in the unexpected case that an error is signaled.
Probably introduced at or before Emacs version 24.1.
Aliases
report-errors (obsolete since 25.1)
Source Code
;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defmacro with-demoted-errors (format &rest body)
"Run BODY and demote any errors to simple messages.
FORMAT is a string passed to `message' to format any error message.
It should contain a single %-sequence; e.g., \"Error: %S\".
If `debug-on-error' is non-nil, run BODY without catching its errors.
This is to be used around code that is not expected to signal an error
but that should be robust in the unexpected case that an error is signaled."
(declare (debug t) (indent 1))
(let* ((err (make-symbol "err"))
(orig-body body)
(format (if (and (stringp format) body) format
(prog1 "Error: %S"
(if format (push format body)))))
(exp
`(condition-case-unless-debug ,err
,(macroexp-progn body)
(error (message ,format ,err) nil))))
(if (eq orig-body body) exp
;; The use without `format' is obsolete, let's warn when we bump
;; into any such remaining uses.
(macroexp-warn-and-return "Missing format argument" exp nil nil format))))