Skip to content

Commit

Permalink
Implement try? a catch-all mechanism that returns nil on error
Browse files Browse the repository at this point in the history
  • Loading branch information
verberktstan committed Jan 23, 2024
1 parent 8bc993f commit e6e50ec
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/swark/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,14 @@
(into {}))))

(def valid-map? (complement invalid-map?))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Try and return nil when something is thrown

(defn try?
"Returns the result of (apply f args). When any error or exception is trown,
returns `nil`."
[f & args]
(try
(apply f args)
#?(:cljs (catch :default nil) :clj (catch Throwable _ nil))))

0 comments on commit e6e50ec

Please sign in to comment.