如何编写测试来处理clojure中的自定义异常

时间:2014-11-22 03:04:27

标签: unit-testing exception clojure

我们如何在clojure中编写测试用例来测试(Exception. "MyCustomException")

引发的自定义异常

我试过(is (thrown? (Exception. "MyCustomException") (method-name param))) 但这不起作用。

PS:我是clojure的新手

1 个答案:

答案 0 :(得分:1)

使用实例?检查是否派生Exception类型的方法=> http://clojuredocs.org/clojure.core/instance_q

(defrecord ExampleExceptionClass [x])

(try
  ;; do something here
  (catch Exception ex
    (instance? ExampleExceptionClass ex)))