mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
signal an error for uncaught throws
* module/language/elisp/boot.el (%catch): New variable. (catch): Bind `%catch' to `t' during the evaluation of `body'. Call `throw' instead of signalling an exception directly. (throw): Signal a `no-catch' error if there is no `catch' to throw to.
This commit is contained in:
parent
8fb678718c
commit
85b3dd6cc2
1 changed files with 6 additions and 3 deletions
|
@ -456,18 +456,21 @@
|
|||
(put 'no-catch 'error-conditions '(no-catch error))
|
||||
(put 'throw 'error-conditions '(throw))
|
||||
|
||||
(defvar %catch nil)
|
||||
|
||||
(defmacro catch (tag &rest body)
|
||||
(let ((tag-value (make-symbol "tag-value"))
|
||||
(c (make-symbol "c"))
|
||||
(data (make-symbol "data")))
|
||||
`(let ((,tag-value ,tag))
|
||||
(condition-case ,c
|
||||
(progn ,@body)
|
||||
(let ((%catch t))
|
||||
,@body)
|
||||
(throw
|
||||
(let ((,data (cdr ,c)))
|
||||
(if (eq (car ,data) ,tag-value)
|
||||
(car (cdr ,data))
|
||||
(signal 'throw ,data))))))))
|
||||
(apply #'throw ,data))))))))
|
||||
|
||||
(defun throw (tag value)
|
||||
(signal 'throw (list tag value)))
|
||||
(signal (if %catch 'throw 'no-catch) (list tag value)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue