Skip to content
This repository was archived by the owner on Mar 20, 2020. It is now read-only.

Commit 3ca3171

Browse files
committed
Merge pull request #1 from philip-doctor/master
sometimes a table must be respected
2 parents 4f19567 + 243edc9 commit 3ca3171

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ When `throw` is not enough.
1616

1717
;; Throw an ex-info exception.
1818
(╯°□°╯︵oɟuᴉ {:some {:extra :data}})
19+
20+
;; Sometimes tables must be respected, and so they may be caught as well
21+
(v°□°v
22+
(/ 1 0)
23+
(┬─┬ ╯°_°╯ ArithmeticException
24+
(log/error ┬─┬)
25+
0))
26+
1927
```
2028

2129
There's no artifact on Clojars¹ but it doesn't matter because you can simply

src/╯°□°╯.clj

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
[throwable]
66
(throw throwable))
77

8+
(defmacro v°□°v
9+
[& body]
10+
(loop [new-body `(try)
11+
[current-form & forms] body]
12+
(if current-form
13+
(if (= (second current-form) '╯°_°╯)
14+
(let [[old-first old-second old-third & others] current-form]
15+
(recur (concat new-body (list `(catch ~old-third ~old-first ~@others)))
16+
forms))
17+
(recur (concat new-body `(~current-form))
18+
forms))
19+
new-body)))
20+
821
(defn ╯°□°╯︵oɟuᴉ
922
"A shorthand for ╯°□°╯ with ex-info."
1023
([map]

test/╯°□°╯_test.clj

+7
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@
1111
(is (thrown-with-msg?
1212
Exception #"^╯°□°╯$"
1313
(╯°□°╯︵oɟuᴉ {}))))
14+
15+
(deftest v°□°v-test
16+
(is (= (v°□°v (/ 1 0) (┬─┬ ╯°_°╯ Exception "caught"))
17+
"caught"))
18+
19+
(is (= (v°□°v (/ 1 0) (┬─┬ ╯°_°╯ Exception (type ┬─┬)))
20+
java.lang.ArithmeticException)))

0 commit comments

Comments
 (0)