(-> 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 (err {:message "foo" :cause (err {:message "bar"})}))
(err {:message "bar"})
Get error cause. ``` => (cause (err {:message "foo" :cause (err {:message "bar"})})) (err {:message "bar"}) ```
(data e)
Get error custom data.
=> (data (err {:message "bar" :data {:hello "world"}}))
{:hello "world"}
Get error custom data. ``` => (data (err {:message "bar" :data {:hello "world"}})) {:hello "world"} ```
(err)
(err {:keys [type message data cause] :or {type default-error-type} :as m})
Returns value as MerrError
.
NOTE Default error type is :error
=> (:type (err {:message "hello"}))
:error
=> (:type (err {:type :custom-error :message "hello"}))
:custom-error
=> (:data (err {:data {:foo "bar"}}))
{:foo "bar"}
Returns value as `MerrError`. **NOTE** Default error type is `:error` ``` => (:type (err {:message "hello"})) :error => (:type (err {:type :custom-error :message "hello"})) :custom-error => (:data (err {:data {:foo "bar"}})) {:foo "bar"} ```
(err? x)
Returns true
if x is MerrError
.
=> (err? "foo")
false
=> (err? (err {:message "foo"}))
true
Returns `true` if x is `MerrError`. ``` => (err? "foo") false => (err? (err {: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 (err? +err+)])
[1 2 false]
=> (let +err+ [a (err {:message "ERR"})
=> b (inc a)]
=> [a b (err? +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 (err? +err+)]) [1 2 false] => (let +err+ [a (err {:message "ERR"}) => b (inc a)] => [a b (err? +err+)]) [nil nil true] ```
(message e)
Get error message.
=> (message (err {:type :foo :message "bar"}))
"bar"
Get error message. ``` => (message (err {:type :foo :message "bar"})) "bar" ```
(try & body)
Returs MerrError
when Exceptions/Errors are thrown.
=> (merr.core/try (throw (ex-info "hello" {})))
err?
=> (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" {}))) err? => (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 (err {:type :foo :message "bar"}))
:foo
Get error type. ``` => (type (err {:type :foo :message "bar"})) :foo ```
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close