diff options
Diffstat (limited to 'devdocs/elisp/error-symbols.html')
| -rw-r--r-- | devdocs/elisp/error-symbols.html | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/devdocs/elisp/error-symbols.html b/devdocs/elisp/error-symbols.html new file mode 100644 index 00000000..6bcc735c --- /dev/null +++ b/devdocs/elisp/error-symbols.html @@ -0,0 +1,17 @@ + <h4 class="subsubsection">Error Symbols and Condition Names</h4> <p>When you signal an error, you specify an <em>error symbol</em> to specify the kind of error you have in mind. Each error has one and only one error symbol to categorize it. This is the finest classification of errors defined by the Emacs Lisp language. </p> <p>These narrow classifications are grouped into a hierarchy of wider classes called <em>error conditions</em>, identified by <em>condition names</em>. The narrowest such classes belong to the error symbols themselves: each error symbol is also a condition name. There are also condition names for more extensive classes, up to the condition name <code>error</code> which takes in all kinds of errors (but not <code>quit</code>). Thus, each error has one or more condition names: <code>error</code>, the error symbol if that is distinct from <code>error</code>, and perhaps some intermediate classifications. </p> <dl> <dt id="define-error">Function: <strong>define-error</strong> <em>name message &optional parent</em> +</dt> <dd><p>In order for a symbol to be an error symbol, it must be defined with <code>define-error</code> which takes a parent condition (defaults to <code>error</code>). This parent defines the conditions that this kind of error belongs to. The transitive set of parents always includes the error symbol itself, and the symbol <code>error</code>. Because quitting is not considered an error, the set of parents of <code>quit</code> is just <code>(quit)</code>. </p></dd> +</dl> <p>In addition to its parents, the error symbol has a <var>message</var> which is a string to be printed when that error is signaled but not handled. If that message is not valid, the error message ‘<samp>peculiar error</samp>’ is used. See <a href="signaling-errors#Definition-of-signal">Definition of signal</a>. </p> <p>Internally, the set of parents is stored in the <code>error-conditions</code> property of the error symbol and the message is stored in the <code>error-message</code> property of the error symbol. </p> <p>Here is how we define a new error symbol, <code>new-error</code>: </p> <div class="example"> <pre class="example">(define-error 'new-error "A new error" 'my-own-errors) +</pre> +</div> <p>This error has several condition names: <code>new-error</code>, the narrowest classification; <code>my-own-errors</code>, which we imagine is a wider classification; and all the conditions of <code>my-own-errors</code> which should include <code>error</code>, which is the widest of all. </p> <p>The error string should start with a capital letter but it should not end with a period. This is for consistency with the rest of Emacs. </p> <p>Naturally, Emacs will never signal <code>new-error</code> on its own; only an explicit call to <code>signal</code> (see <a href="signaling-errors#Definition-of-signal">Definition of signal</a>) in your code can do this: </p> <div class="example"> <pre class="example">(signal 'new-error '(x y)) + error→ A new error: x, y +</pre> +</div> <p>This error can be handled through any of its condition names. This example handles <code>new-error</code> and any other errors in the class <code>my-own-errors</code>: </p> <div class="example"> <pre class="example">(condition-case foo + (bar nil t) + (my-own-errors nil)) +</pre> +</div> <p>The significant way that errors are classified is by their condition names—the names used to match errors with handlers. An error symbol serves only as a convenient way to specify the intended error message and list of condition names. It would be cumbersome to give <code>signal</code> a list of condition names rather than one error symbol. </p> <p>By contrast, using only error symbols without condition names would seriously decrease the power of <code>condition-case</code>. Condition names make it possible to categorize errors at various levels of generality when you write an error handler. Using error symbols alone would eliminate all but the narrowest level of classification. </p> <p>See <a href="standard-errors">Standard Errors</a>, for a list of the main error symbols and their conditions. </p><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br> + <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Error-Symbols.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Error-Symbols.html</a> + </p> +</div> |
