tangled
alpha
login
or
join now
noahbogart.com
/
sinker
0
fork
atom
catch exceptions hook, line, and sinker
0
fork
atom
overview
issues
pulls
pipelines
Switch cond to nested if to avoid double call
noahbogart.com
6 months ago
a38c308e
949fa8b4
+6
-24
2 changed files
expand all
collapse all
unified
split
example.clj
src
noahtheduke
sinker.clj
-16
example.clj
···
1
1
-
(ns example
2
2
-
(:require
3
3
-
[noahtheduke.sinker :refer [try+]]))
4
4
-
5
5
-
(defn pred?
6
6
-
[data]
7
7
-
(= :value (:key data)))
8
8
-
9
9
-
(try+ (+ 1 2)
10
10
-
(catch ::special-exception
11
11
-
10)
12
12
-
(catch pred? ex
13
13
-
(ex-message ex))
14
14
-
(catch #'pred? ex
15
15
-
(ex-message ex))
16
16
-
)
+6
-8
src/noahtheduke/sinker.clj
···
19
19
{:type :catch/type}]
20
20
[(symbol? pred)
21
21
(let [klass (resolve pred)]
22
22
-
(cond+
23
23
-
[(and (class? klass) (= "clojure.lang.ExceptionInfo" (.getName ^Class klass)))
24
24
-
{:type :catch/raw}]
25
25
-
[(class? klass)
26
26
-
{:type :catch/class
27
27
-
:pred klass}]
28
28
-
[:else
29
29
-
{:type :catch/fn}]))]
22
22
+
(if (class? klass)
23
23
+
(if (= "clojure.lang.ExceptionInfo" (.getName ^Class klass))
24
24
+
{:type :catch/raw}
25
25
+
{:type :catch/class
26
26
+
:pred klass})
27
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)