summaryrefslogtreecommitdiff
path: root/module/language/elisp
diff options
context:
space:
mode:
authorBT Templeton <bpt@hcoop.net>2011-08-12 16:34:16 -0400
committerBT Templeton <bpt@hcoop.net>2012-02-03 18:53:50 -0500
commit85b3dd6cc2ca2102058a9c3db7b81d4015cfb0e3 (patch)
treefe3b7cae14055dc20990050cf03fce4fa325dbcb /module/language/elisp
parent8fb678718ca38089d873a3d91ab9530e9bb7f15f (diff)
downloadguile-85b3dd6cc2ca2102058a9c3db7b81d4015cfb0e3.tar.gz
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.
Diffstat (limited to 'module/language/elisp')
-rw-r--r--module/language/elisp/boot.el9
1 files changed, 6 insertions, 3 deletions
diff --git a/module/language/elisp/boot.el b/module/language/elisp/boot.el
index a183b89e4..3e0a748ab 100644
--- a/module/language/elisp/boot.el
+++ b/module/language/elisp/boot.el
@@ -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)))