How to throw an exception that the say exercise test recognizes?

The say exercise tests for out-of-range inputs, expecting an IllegalArgumentException. I’ve added code that throws those exceptions (at least, they show up in my REPL). But the Exercism test runner fails my code:

CODE RUN
(is (thrown? IllegalArgumentException (say/number -1)))
TEST ERROR
An unexpected error occurred:
java.lang.Exception: IllegalArgumentException

I don’t see any hints for this exercise, and I could use one (or more) for throwing exceptions that will meet the test.

(throw (Exception. "Some text"))

This might be the hint you are looking for. If this is a practice exercise, then I am not surprised that there is no hint. Searching documentation to answer such questions is a skill that is probably assumed for those practicing the language.

If this is a concept exercise, then it might be expected that this very question is answered in the form of a prior exercise, or the documentation for this one if exceptions are the focused concept, or even only a required concept among others for this concept exercise.

I do not do much in the way of Clojure, but I hope that is helpful.

Thank you, kotp. I did figure that out and code it.

If I’m reading the test results correctly, it’s saying that I have thrown the IllegalArgumentException, but it is still giving me a fail. There may be a nuance that I’m missing.

It is always best to show your code and the communication you get back. This lets someone know more of the story.

The output indicates that an Exception is thrown instead of IllegalArgumentException.

Thank you, kotp,

Here’s my code that throw an exception for negative numbers:

(cond 
  (< num 0) (throw (Exception. "IllegalArgumentException"))
  ; . . .
)

Thank you, tasx.

That’s what I was missing – I thought I was throwing the specific type of exception, but was only throwing a generic exception.

(throw (IllegalArgumentException. "IllegalArgumentException")

This does throw Exception not IllegalArgumentException, just as you wrote it. Re-read the error message?

And because you were throwing a generic Exception, this made the tests themselves throw an Exception telling you that this is an illegal argument instead of just passing without errors :)

Thank you for the fast and helpful replies, both kotp and tasx!