special form | since v0.0-927 | clojure.core/throw | Edit |
(throw expr)
expr
is evaluated and thrown, hopefully to be caught by a try
expression.
(throw (js/Error. "Oops!"))
The expr is evaluated and thrown.
(defmethod parse 'throw
[op env [_ throw-form :as form] name _]
(cond
(= 1 (count form))
(throw
(error env "Too few arguments to throw, throw expects a single Error instance"))
(< 2 (count form))
(throw
(error env "Too many arguments to throw, throw expects a single Error instance")))
(let [throw-expr (disallowing-recur (analyze (assoc env :context :expr) throw-form))]
{:env env :op :throw :form form
:exception throw-expr
:children [:exception]}))
(defmethod emit* :throw
[{throw :exception :keys [env]}]
(if (= :expr (:context env))
(emits "(function(){throw " throw "})()")
(emitln "throw " throw ";")))