throw

special formsince v0.0-927 clojure.core/throwEdit
(throw expr)

Details:

expr is evaluated and thrown, hopefully to be caught by a try expression.

(throw (js/Error. "Oops!"))


See Also:


Source docstring:
The expr is evaluated and thrown.
Parser code @ clojurescript:src/main/clojure/cljs/analyzer.cljc
(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]}))

Emitting code @ clojurescript:src/main/clojure/cljs/compiler.cljc
(defmethod emit* :throw
  [{throw :exception :keys [env]}]
  (if (= :expr (:context env))
    (emits "(function(){throw " throw "})()")
    (emitln "throw " throw ";")))