mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 00:40:30 -05:00
✨ Add better exception macros (ignoring and try).
This commit is contained in:
parent
823aa426ed
commit
f57941fd7c
1 changed files with 9 additions and 8 deletions
|
@ -25,23 +25,24 @@
|
|||
[& {:keys [type code message hint cause] :as params}]
|
||||
(s/assert ::error-params params)
|
||||
(let [message (or message hint "")
|
||||
payload (dissoc params :cause :message)]
|
||||
payload (dissoc params :cause)]
|
||||
(ex-info message payload cause)))
|
||||
|
||||
(defmacro raise
|
||||
[& args]
|
||||
`(throw (error ~@args)))
|
||||
|
||||
(defn ignoring*
|
||||
[f]
|
||||
(try
|
||||
(f)
|
||||
(catch #?(:clj Exception :cljs :default) e
|
||||
nil)))
|
||||
(defn try*
|
||||
[f on-error]
|
||||
(try (f) (catch #?(:clj Exception :cljs :default) e (on-error e))))
|
||||
|
||||
;; 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)))
|
||||
`(try* (^:once fn* [] ~@exprs) (constantly nil)))
|
||||
|
||||
(defmacro try
|
||||
[& exprs]
|
||||
`(try* (^:once fn* [] ~@exprs) identity))
|
||||
|
|
Loading…
Reference in a new issue