Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Keep locals in dce.

  • Loading branch information...
commit 56838c4d3c29a1336e66d4a77ce67ada1e41efb1 1 parent 370c03b
@technomancy authored
Showing with 23 additions and 7 deletions.
  1. +15 −6 src/dce/Exception.clj
  2. +8 −1 test/dce/test/exception.clj
View
21 src/dce/Exception.clj
@@ -70,11 +70,20 @@
(defn -count [self]
(count (.state self)))
-(defn throw+
+(defn- locals [env]
+ (into {} (for [[n _] env]
+ [(list 'quote n) n])))
+
+(defmacro throw+
([x]
- (throw
- (if (instance? Throwable x)
- x
- (dce.Exception. x))))
+ `(let [x# ~x]
+ (throw
+ (if (instance? Throwable x#)
+ x#
+ (dce.Exception.
+ (if (:locals x#)
+ x#
+ (assoc x# :locals ~(locals &env))))))))
([k v & kvs]
- (throw+ (apply hash-map k v kvs))))
+ (let [m (apply hash-map k v kvs)]
+ `(throw+ ~m))))
View
9 test/dce/test/exception.clj
@@ -60,6 +60,8 @@
:bummer-dude)
(catch funky? x#
:external-pred)
+ (catch :locals e#
+ e#)
(catch Exception _#
:exception)))
@@ -70,4 +72,9 @@
(throw+ (Exception. "whoops")))))
(is (= :external-pred (mega-try
(throw+ :funkiness :most-excellent))))
- (is (thrown? Throwable (mega-try (throw+ (Throwable. "hi'"))))))
+ (is (thrown? Throwable (mega-try (throw+ (Throwable. "hi"))))))
+
+(deftest test-locals
+ (is (= :not-variable ('a-local (:locals (mega-try
+ (let [a-local :not-variable]
+ (throw+ {}))))))))
Please sign in to comment.
Something went wrong with that request. Please try again.