Welcome! Please see the About page for a little more info on how this works.

+3 votes
ago in Errors by

It is, of course, an error to call (even? (range)), but still - I'd much rather prefer a class cast exception. Or the existing IllegalArgumentException, just without printing the argument. Especially given that the argument could be absolutely anything, including side-effecting lazy collections.

A couple of other cases like this:

(array-map (range))
(requiring-resolve (range))
ago by
https://github.com/clojure/clojure/blob/da1c748123c80fa3e82e24fc8e24a950a3ebccd9/src/clj/clojure/core.clj#L1406

It's because the `IllegalArgumentException` (which, as you noticed, is correctly thrown) tries to be a bit too helpful and include the input argument in the exception message as a string - and the string representation of the input takes forever to compute.

Interesting find!
ago by
a good opportunity for `(type n)` in that message
ago by
I've also run into similar issues. My use case was working on dev tools that can generically search arbitrary clojure data in the repl using predicates. For example, you could search a repl value for any nested `even?` numbers. Even if the search itself is incremental and careful to not fully realize any values and supports interruption, you can run into problems where the predicate will throw an exception that tries to fully realize its argument by printing it.

Please log in or register to answer this question.

...