aboutsummaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorStefan Monnier2026-03-08 19:11:13 -0400
committerStefan Monnier2026-03-08 19:11:13 -0400
commit0df94040fcf76bb894cd24f7242fd40aba67bb3f (patch)
treeddb4819c9989f75c675af1f5d1e3ee6ec4b20d66 /src/eval.c
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 'src/eval.c')
-rw-r--r--src/eval.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/eval.c b/src/eval.c
index 7ca9d761a7e..0b451b2c891 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1871,10 +1871,15 @@ probably_quit (void)
1871 unbind_to (gc_count, Qnil); 1871 unbind_to (gc_count, Qnil);
1872} 1872}
1873 1873
1874DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0, 1874DEFUN ("signal", Fsignal, Ssignal, 1, 2, 0,
1875 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA. 1875 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1876This function does not return. 1876This function does not return.
1877 1877
1878When signaling a new error, the DATA argument is mandatory.
1879When re-signaling an error to propagate it to further handlers,
1880DATA has to be omitted and the first argument has to be the whole
1881error descriptor.
1882
1878When `noninteractive' is non-nil (in particular, in batch mode), an 1883When `noninteractive' is non-nil (in particular, in batch mode), an
1879unhandled error calls `kill-emacs', which terminates the Emacs 1884unhandled error calls `kill-emacs', which terminates the Emacs
1880session with a non-zero exit code. 1885session with a non-zero exit code.
@@ -1942,13 +1947,14 @@ signal_or_quit (Lisp_Object error_symbol, Lisp_Object data, bool continuable)
1942 /* FIXME: 'handler-bind' makes `signal-hook-function' obsolete? */ 1947 /* FIXME: 'handler-bind' makes `signal-hook-function' obsolete? */
1943 /* FIXME: Here we still "split" the error object 1948 /* FIXME: Here we still "split" the error object
1944 into its error-symbol and its error-data? */ 1949 into its error-symbol and its error-data? */
1945 calln (Vsignal_hook_function, error_symbol, data); 1950 calln (Vsignal_hook_function, real_error_symbol,
1951 NILP (data) && CONSP (error) ? XCDR (error) : data);
1946 unbind_to (count, Qnil); 1952 unbind_to (count, Qnil);
1947 } 1953 }
1948 1954
1949 conditions = Fget (real_error_symbol, Qerror_conditions); 1955 conditions = Fget (real_error_symbol, Qerror_conditions);
1950 if (NILP (conditions)) 1956 if (NILP (conditions))
1951 signal_error ("Invalid error symbol", error_symbol); 1957 signal_error ("Invalid error symbol", real_error_symbol);
1952 1958
1953 /* Remember from where signal was called. Skip over the frame for 1959 /* Remember from where signal was called. Skip over the frame for
1954 `signal' itself. If a frame for `error' follows, skip that, 1960 `signal' itself. If a frame for `error' follows, skip that,