Skip to content

Instantly share code, notes, and snippets.

@zakwilson
Created April 18, 2016 00:22
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/3bf230af666d560b8f2c1b6dbed578a6 to your computer and use it in GitHub Desktop.
Save zakwilson/3bf230af666d560b8f2c1b6dbed578a6 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