Skip to content

Instantly share code, notes, and snippets.

(try
(d/catch (d/chain (throw (ex-info "standard failure" {:type :foo})))
(fn [e]
(println "d/catch e" (.getMessage e))))
(catch Exception e
(println "try/catch e" (.getMessage e))))
(try
(d/catch (d/chain (d/error-deferred (ex-info "deferred error" {:type :bar})))
(fn [e]
@alexanderjamesking
alexanderjamesking / errors.clj
Created October 7, 2021 20:02 — forked from adambard/errors.clj
An example of functional error handling in clojure.
(ns example.errors)
(defn clean-address [params]
"Ensure (params :address) is present"
(if (empty? (params :address))
[nil "Please enter your address"]
[params nil]))
(defn clean-email [params]
"Ensure (params :email) matches *@*.*"
(defn task-list []
(let [visible-todos @(subscribe [:visible-todos])
all-complete? @(subscribe [:all-complete?])]
[:section#main
[:input#toggle-all
{:type "checkbox"
:checked all-complete?
:on-change #(dispatch [:complete-all-toggle])}]
[:label
{:for "toggle-all"}