Created
April 28, 2018 11:47
-
-
Save beetleman/ffc30589a5bda34ea4db75e1d7a95e71 to your computer and use it in GitHub Desktop.
how to use clojure `ex-info`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns erc20-mapper.ex-tutorial) | |
(defn fail [& args] | |
(throw (ex-info "OMG!" {:type ::fail :args args}))) | |
(defn funky-fail [& args] | |
(throw (ex-info "jayyyyy!" {:type ::funky-fail :args args}))) | |
(defn mby [fn] | |
(try | |
(fn) | |
(catch clojure.lang.ExceptionInfo e | |
(case (-> e ex-data :type) | |
::fail "yes!" | |
::funky-fail "hell yes!" | |
(throw e))))) | |
(mby fail) ;; => "yes!" | |
(mby funky-fail) ;; => "hell yes!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment