aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorStefan Monnier2026-03-08 19:11:13 -0400
committerStefan Monnier2026-03-08 19:11:13 -0400
commit0df94040fcf76bb894cd24f7242fd40aba67bb3f (patch)
treeddb4819c9989f75c675af1f5d1e3ee6ec4b20d66 /doc
parenta3dda7e5252f8fff33a60dc455c4a25ea5904edd (diff)
downloademacs-0df94040fcf76bb894cd24f7242fd40aba67bb3f.tar.gz
emacs-0df94040fcf76bb894cd24f7242fd40aba67bb3f.zip
Improve the error API
Define new functions to manipulate error descriptors and add support for `signal` to *re*signal a previous error. * src/eval.c (Fsignal): Make the second arg optional and document the possibility of passing a whole error descriptor to re-signal it. (signal_or_quit): Fix a few corner case issues when DATA is `nil` and ERROR_SYMBOL is an error descriptor. * lisp/subr.el (error-type-p, error--p, error-type, error-data) (error-has-type-p, error-slot-value): New function. * doc/lispref/control.texi (Handling Errors): Prefer "error descriptor" to "error description". Use the new single-arg call to `signal` to re-throw an error. Document `error-type`, `error-data` and `error-slot-value`. (Error Symbols): Document the new functions `error-type-p` and `error-has-type-p`.
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/control.texi41
1 files changed, 35 insertions, 6 deletions
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi
index a7d605cf0a0..3925bdd1b40 100644
--- a/doc/lispref/control.texi
+++ b/doc/lispref/control.texi
@@ -2447,12 +2447,13 @@ as the overall value.
2447The argument @var{var} is a variable. @code{condition-case} does not 2447The argument @var{var} is a variable. @code{condition-case} does not
2448bind this variable when executing the @var{protected-form}, only when it 2448bind this variable when executing the @var{protected-form}, only when it
2449handles an error. At that time, it binds @var{var} locally to an 2449handles an error. At that time, it binds @var{var} locally to an
2450@dfn{error description}, which is a list giving the particulars of the 2450@dfn{error descriptor}, also sometimes called error description,
2451error. The error description has the form @code{(@var{error-symbol} 2451which is a list giving the particulars of the error.
2452The error descriptor has the form @code{(@var{error-symbol}
2452. @var{data})}. The handler can refer to this list to decide what to 2453. @var{data})}. The handler can refer to this list to decide what to
2453do. For example, if the error is for failure opening a file, the file 2454do. For example, if the error is for failure opening a file, the file
2454name is the second element of @var{data}---the third element of the 2455name is the second element of @var{data}---the third element of the
2455error description. 2456error descriptor.
2456 2457
2457If @var{var} is @code{nil}, that means no variable is bound. Then the 2458If @var{var} is @code{nil}, that means no variable is bound. Then the
2458error symbol and associated data are not available to the handler. 2459error symbol and associated data are not available to the handler.
@@ -2469,15 +2470,31 @@ Sometimes it is necessary to re-throw a signal caught by
2469how to do that: 2470how to do that:
2470 2471
2471@example 2472@example
2472 (signal (car err) (cdr err)) 2473 (signal err)
2473@end example 2474@end example
2474 2475
2475@noindent 2476@noindent
2476where @code{err} is the error description variable, the first argument 2477where @code{err} is the error descriptor variable, the first argument
2477to @code{condition-case} whose error condition you want to re-throw. 2478to @code{condition-case} whose error condition you want to re-throw.
2478@xref{Definition of signal}. 2479@xref{Definition of signal}.
2479@end defspec 2480@end defspec
2480 2481
2482@defun error-type error
2483This function returns the error symbol of the error descriptor @var{error}.
2484@end defun
2485
2486@defun error-data error
2487This function returns the data of the error descriptor @var{error}.
2488@end defun
2489
2490@defun error-slot-value error pos
2491This function returns the value in the field number @var{pos} of the error
2492descriptor @var{error}. The fields are numbered starting with 1. E.g.,
2493for an error of type @code{wrong-type-argument}, @code{(error-slot-value
2494@var{error} 2)} returns the object that failed the type test, and
2495@code{(error-slot-value @var{error} 1)} returns the predicate that failed.
2496@end defun
2497
2481@defun error-message-string error-descriptor 2498@defun error-message-string error-descriptor
2482This function returns the error message string for a given error 2499This function returns the error message string for a given error
2483descriptor. It is useful if you want to handle an error by printing the 2500descriptor. It is useful if you want to handle an error by printing the
@@ -2615,7 +2632,7 @@ Emacs searches all the active @code{condition-case} and
2615specifies one or more of these condition names. When the innermost 2632specifies one or more of these condition names. When the innermost
2616matching handler is one installed by @code{handler-bind}, the 2633matching handler is one installed by @code{handler-bind}, the
2617@var{handler} function is called with a single argument holding the 2634@var{handler} function is called with a single argument holding the
2618error description. 2635error descriptor.
2619 2636
2620Contrary to what happens with @code{condition-case}, @var{handler} is 2637Contrary to what happens with @code{condition-case}, @var{handler} is
2621called in the dynamic context where the error happened. This means it 2638called in the dynamic context where the error happened. This means it
@@ -2799,6 +2816,18 @@ make it possible to categorize errors at various levels of generality
2799when you write an error handler. Using error symbols alone would 2816when you write an error handler. Using error symbols alone would
2800eliminate all but the narrowest level of classification. 2817eliminate all but the narrowest level of classification.
2801 2818
2819@defun error-type-p symbol
2820This function returns non-@code{nil} if @var{symbol} is a valid
2821error condition name.
2822@end defun
2823
2824@defun error-has-type-p error condition
2825This function tests whether @var{condition} is a parent of the error
2826symbol of the error descriptor @var{error}.
2827It returns non-@code{nil} if the type of the error descriptor
2828@var{error} belongs to the condition name @var{condition}.
2829@end defun
2830
2802 @xref{Standard Errors}, for a list of the main error symbols 2831 @xref{Standard Errors}, for a list of the main error symbols
2803and their conditions. 2832and their conditions.
2804 2833