title: How to test for thrown exceptions in Clojure?
body: <p>When testing code I like to cover failing conditions, too.</p>
  
  <p>I'm new to Clojure, but is it somehow possible to test for a thrown exception?</p>
  
  <p>I'd like to test the following sample code:</p>
  
  <pre><code>(ns com.stackoverflow.clojure.tests)
  
  (defn casetest [x]
    (case x
      "a" "An a."
      "b" "A b."
      (-&gt; (clojure.core/format "Expression '%s' not defined." x)
          (IllegalArgumentException.)
          (throw))))
  </code></pre>
  
  <p>with the following test-methods:</p>
  
  <pre><code>(ns com.stackoverflow.clojure.tests-test
    (:require [clojure.test :refer :all]
              [com.stackoverflow.clojure.tests :refer :all]))
  
  (deftest casetest-tests
    (is (= "An a." (casetest "a")))
    (is (= "A b."  (casetest "b")))
    (throws-excpeption IllegalArgumentException. (casetest "c")) ; conceptual code
    )
  
  (run-tests)
  </code></pre>
  
  <p>My project.clj looks like:</p>
  
  <pre><code>(defproject com.stackoverflow.clojure/tests "0.1.0-SNAPSHOT"
    :description "Tests of Clojure test-framework."
    :url "http://example.com/FIXME"
    :license {:name "Eclipse Public License"
              :url "http://www.eclipse.org/legal/epl-v10.html"}
    :dependencies [[org.clojure/clojure "1.6.0"]])
  </code></pre>