【发布时间】:2015-02-19 15:21:09
【问题描述】:
我无法捕捉来自map 的第二次递归调用的抛出。
出于某种原因,来自(call-rec (first node)) 的异常冒泡,但不是来自(map call-rec node)。
考虑以下示例:
(deftest recursion-test
(testing "Testing recursion throws" ;; => OK
(is (thrown? Exception
(map #(throw (Exception. "e") [:a :b])))))
(testing "Testing throws from recursion lvl 1" ;; => OK
(is (thrown?
Exception
(letfn [(call-rec [node]
(cond
(vector? node)
(do
(throw (Exception. "e"))
(map call-rec node))
:else
node))]
(call-rec [:one :two])))))
(testing "Testing throws from map recursion lvl 2" ;; => FAILURE
(is (thrown? Exception
(letfn [(call-rec [node]
(cond
(vector? node)
(map call-rec node)
:else
(throw (Exception. "e"))
))]
(call-rec [:one :two])))))
(testing "Testing throws from first recursion lvl 2" ;; => OK
(is (thrown? Exception
(letfn [(call-rec [node]
(cond
(vector? node)
(call-rec (first node))
:else
(throw (Exception. "e"))
))]
(call-rec [:one :two]))))))
【问题讨论】: