Next: , Previous: , Up: Errors—Unintentional Nonlocal Exits   [Index]


F.6.2.4 Ignoring Errors

Ignoring Errors Concepts

Macro: ignore-errors body…

This construct executes ‘BODY’, ignoring any errors that occur during its execution. If the execution is without error, ignore-errors returns the value of the last form in body; otherwise, it returns ‘nil’.

Here’s the example at the beginning of this subsection rewritten using ignore-errors:

(ignore-errors
   (delete-file filename))
Macro: ignore-error condition body…

This macro is like ignore-errors, but will only ignore the specific error condition specified. ‘CONDITION’ can also be a list of error conditions.

(ignore-error end-of-file
    (read ""))
Macro: with-demoted-errors format body…

This macro is like a milder version of ignore-errors. Rather than suppressing errors altogether, it converts them into messages. It uses the string ‘FORMAT’ to format the message. ‘FORMAT’ should contain a single ‘%’-sequence; e.g., "Error: %S". Use with-demoted-errors around code that is not expected to signal errors, but should be robust if one does occur. Note that this macro uses condition-case-unless-debug rather than condition-case.