>From a quick glance, it looks like the exceptions that are *not* being
caught are those generated by the compiler, who can't understand the code.
 test-is can't find those because the code doesn't even run in that case.

On Thu, Feb 5, 2009 at 8:33 AM, Frantisek Sodomka <fsodo...@gmail.com>wrote:

> Hello Stuart and all!
>
> There is something strange going on with (is (thrown? ...)) form:
>
> user=> (use 'clojure.contrib.test-is)
> nil
> user=> (is (= 2 2))
> true
>
> ; this works
> user=> (/ 1 0)
> java.lang.ArithmeticException: Divide by zero (NO_SOURCE_FILE:0)
> user=> (is (thrown? ArithmeticException (/ 1 0)))
> #<ArithmeticException java.lang.ArithmeticException: Divide by zero>
>
> ; this doesn't work
> user=> (if)
> java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:10)
> user=> (is (thrown? Exception (if)))
> java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:13)
>
> user=> (if true)
> java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:29)
> user=> (is (thrown? Exception (if true)))
> java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:14)
>
> ; this works
> user=> (- 2)
> -2
> user=> (-)
> java.lang.IllegalArgumentException: Wrong number of args passed to: core$-
> (NO_SOURCE_FILE:0)
> user=> (is (thrown? IllegalArgumentException (-)))
> #<IllegalArgumentException java.lang.IllegalArgumentException: Wrong number
> of args passed to: core$->
>
> Even though 'if' is a special form, shouldn't (is (thrown? Exception (if)))
> catch the Exception correctly? Also, notice that (if) throws different
> exception than (-) - would it make sense to unify these exceptions?
>
> Another example:
>
> user=> (vals {:a 1 :b 2})
> (1 2)
> user=> (vals [1 2])
> java.lang.ClassCastException: java.lang.Integer cannot be cast to
> java.util.Map$Entry
> (user=> (is (thrown? ClassCastException (vals [1 2])))
>
> FAIL in  (:20)
> expected: (thrown? ClassCastException (vals [1 2]))
>   actual: nil
> nil
>
> We can see that exception doesn't get processed/caught correctly.
>
> Also see REPL - it prints redundant "(" character after exception was
> thrown. Hitting ENTER fixes it:
>
> user=> (vals [1 2])
> java.lang.ClassCastException: java.lang.Integer cannot be cast to
> java.util.Map$Entry
> (user=>
> user=>
>
> Thank you for looking at this, Frantisek
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to