From 0a34aa6231d420577c5bd1400c6900297269e78c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 5 Oct 2020 18:18:58 +0200 Subject: [PATCH] :tada: Add `ex/ignoring` macro. --- common/app/common/exceptions.cljc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common/app/common/exceptions.cljc b/common/app/common/exceptions.cljc index ee1370279f..2ff5b73cc1 100644 --- a/common/app/common/exceptions.cljc +++ b/common/app/common/exceptions.cljc @@ -31,3 +31,17 @@ (defmacro raise [& args] `(throw (error ~@args))) + +(defn ignoring* + [f] + (try + (f) + (catch #?(:clj Exception :cljs :default) e + nil))) + +;; http://clj-me.cgrand.net/2013/09/11/macros-closures-and-unexpected-object-retention/ +;; Explains the use of ^:once metadata + +(defmacro ignoring + [& exprs] + `(ignoring* (^:once fn* [] ~@exprs)))