catch exceptions hook, line, and sinker

Switch cond to nested if to avoid double call

+6 -24
-16
example.clj
··· 1 - (ns example 2 - (:require 3 - [noahtheduke.sinker :refer [try+]])) 4 - 5 - (defn pred? 6 - [data] 7 - (= :value (:key data))) 8 - 9 - (try+ (+ 1 2) 10 - (catch ::special-exception 11 - 10) 12 - (catch pred? ex 13 - (ex-message ex)) 14 - (catch #'pred? ex 15 - (ex-message ex)) 16 - )
+6 -8
src/noahtheduke/sinker.clj
··· 19 19 {:type :catch/type}] 20 20 [(symbol? pred) 21 21 (let [klass (resolve pred)] 22 - (cond+ 23 - [(and (class? klass) (= "clojure.lang.ExceptionInfo" (.getName ^Class klass))) 24 - {:type :catch/raw}] 25 - [(class? klass) 26 - {:type :catch/class 27 - :pred klass}] 28 - [:else 29 - {:type :catch/fn}]))] 22 + (if (class? klass) 23 + (if (= "clojure.lang.ExceptionInfo" (.getName ^Class klass)) 24 + {:type :catch/raw} 25 + {:type :catch/class 26 + :pred klass}) 27 + {:type :catch/fn}))] 30 28 [(and (seq? pred) (symbol? (first pred)) (= "var" (name (first pred)))) 31 29 {:type :catch/fn}] 32 30 [(nil? pred)