Skip to content

Instantly share code, notes, and snippets.

@zakwilson
Created April 18, 2016 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakwilson/dd8b9f2048f826467f3443016e811857 to your computer and use it in GitHub Desktop.
Save zakwilson/dd8b9f2048f826467f3443016e811857 to your computer and use it in GitHub Desktop.
(defmacro silence-errors [& body]
"Evaluate body and return the result, or nil if an exception is thrown"
`(try ~@body
(catch Exception e#)))
(defmacro first-truthy [& body]
"Try some expressions; return the result of the first one that neither throws an exception or returns false or nil"
(cons 'or (map (fn [item]
(list 'silence-errors item))
`~body)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment