Add `define-error` on 24.3
authorVasilij Schneidermann <v.schneidermann@gmail.com>
Tue, 1 Mar 2016 22:40:16 +0000 (23:40 +0100)
committerVasilij Schneidermann <v.schneidermann@gmail.com>
Tue, 1 Mar 2016 22:40:16 +0000 (23:40 +0100)
elisp/types.el

index cf176b1..8029e5e 100644 (file)
 
 ;;; errors
 
+(when (not (fboundp 'define-error))
+  (defun define-error (name message &optional parent)
+  "Define NAME as a new error signal.
+MESSAGE is a string that will be output to the echo area if such an error
+is signaled without being caught by a `condition-case'.
+PARENT is either a signal or a list of signals from which it inherits.
+Defaults to `error'."
+  (unless parent (setq parent 'error))
+  (let ((conditions
+         (if (consp parent)
+             (apply #'nconc
+                    (mapcar (lambda (parent)
+                              (cons parent
+                                    (or (get parent 'error-conditions)
+                                        (error "Unknown signal `%s'" parent))))
+                            parent))
+           (cons parent (get parent 'error-conditions)))))
+    (put name 'error-conditions
+         (delete-dups (copy-sequence (cons name conditions))))
+    (when message (put name 'error-message message)))))
+
 (define-error 'mal "MAL error")
 (define-error 'unterminated-sequence "Unterminated token sequence" 'mal)
 (define-error 'end-of-token-stream "End of token stream" 'mal)