Skip to content

Instantly share code, notes, and snippets.

@beetleman
Created April 28, 2018 11:47
Show Gist options
  • Save beetleman/ffc30589a5bda34ea4db75e1d7a95e71 to your computer and use it in GitHub Desktop.
Save beetleman/ffc30589a5bda34ea4db75e1d7a95e71 to your computer and use it in GitHub Desktop.
how to use clojure `ex-info`
(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