(-> x & forms)
Threads the expr through the forms. Inserts x as the
second item in the first form, making a list of it if it is not a
list already. If there are more forms, inserts the first form as the
second item in second form, etc.
Return MerrError
on the spot when there is on the way.
=> (-> 1 inc (- 1))
1
=> (letfn [(failinc [_] (err))]
=> (-> 1 inc failinc inc))
(err)
Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the second item in second form, etc. Return `MerrError` on the spot when there is on the way. ``` => (-> 1 inc (- 1)) 1 => (letfn [(failinc [_] (err))] => (-> 1 inc failinc inc)) (err) ```
(->> x & forms)
Threads the expr through the forms. Inserts x as the
second item in the first form, making a list of it if it is not a
list already. If there are more forms, inserts the first form as the
second item in second form, etc.
Return MerrError
on the spot when there is on the way.
=> (->> 1 inc (- 1))
-1
=> (letfn [(failinc [_] (err))]
=> (->> 1 inc failinc inc))
(err)
Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the second item in second form, etc. Return `MerrError` on the spot when there is on the way. ``` => (->> 1 inc (- 1)) -1 => (letfn [(failinc [_] (err))] => (->> 1 inc failinc inc)) (err) ```
(cause e)
Get error cause.
=> (cause (error {:message "foo" :cause (error {:message "bar"})}))
(error {:message "bar"})
Get error cause. ``` => (cause (error {:message "foo" :cause (error {:message "bar"})})) (error {:message "bar"}) ```
(data e)
Get error custom data.
=> (data (error {:message "bar" :data {:hello "world"}}))
{:hello "world"}
Get error custom data. ``` => (data (error {:message "bar" :data {:hello "world"}})) {:hello "world"} ```
(error)
(error {:keys [type message data cause] :or {type default-error-type} :as m})
Returns value as MerrError
.
NOTE Default error type is :error
=> (:type (error {:message "hello"}))
:error
=> (:type (error {:type :custom-error :message "hello"}))
:custom-error
=> (:data (error {:data {:foo "bar"}}))
{:foo "bar"}
Returns value as `MerrError`. **NOTE** Default error type is `:error` ``` => (:type (error {:message "hello"})) :error => (:type (error {:type :custom-error :message "hello"})) :custom-error => (:data (error {:data {:foo "bar"}})) {:foo "bar"} ```
(error? x)
Returns true
if x is MerrError
.
=> (error? "foo")
false
=> (error? (error {:message "foo"}))
true
Returns `true` if x is `MerrError`. ``` => (error? "foo") false => (error? (error {:message "foo"})) true ```
(let err-sym bindings & body)
binding => binding-form init-expr
If init-expr is not MerrError
, binding-form bound to the value,
if not, err-sym
bound to the MerrError
value and rest bindings are skipped.
=> (let +err+ [a 1
=> b (inc a)]
=> [a b (error? +err+)])
[1 2 false]
=> (let +err+ [a (error {:message "ERR"})
=> b (inc a)]
=> [a b (error? +err+)])
[nil nil true]
binding => binding-form init-expr If init-expr is not `MerrError`, binding-form bound to the value, if not, `err-sym` bound to the `MerrError` value and rest bindings are skipped. ``` => (let +err+ [a 1 => b (inc a)] => [a b (error? +err+)]) [1 2 false] => (let +err+ [a (error {:message "ERR"}) => b (inc a)] => [a b (error? +err+)]) [nil nil true] ```
(message e)
Get error message.
=> (message (error {:type :foo :message "bar"}))
"bar"
Get error message. ``` => (message (error {:type :foo :message "bar"})) "bar" ```
(try & body)
Returs MerrError
when Exceptions/Errors are thrown.
=> (merr.core/try (throw (ex-info "hello" {})))
error?
=> (type (merr.core/try {:type :test} (throw (ex-info "hello" {}))))
:test
=> (type (merr.core/try (throw (ex-info "hello" {:merr/type :test}))))
:test
=> (data (merr.core/try {:data {:bar 2}} (throw (ex-info "hello" {:foo 1}))))
{:foo 1, :bar 2}
Returs `MerrError` when Exceptions/Errors are thrown. ``` => (merr.core/try (throw (ex-info "hello" {}))) error? => (type (merr.core/try {:type :test} (throw (ex-info "hello" {})))) :test => (type (merr.core/try (throw (ex-info "hello" {:merr/type :test})))) :test => (data (merr.core/try {:data {:bar 2}} (throw (ex-info "hello" {:foo 1})))) {:foo 1, :bar 2} ```
(type e)
Get error type.
=> (type (error {:type :foo :message "bar"}))
:foo
Get error type. ``` => (type (error {:type :foo :message "bar"})) :foo ```
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close