Is there any way to specify the error message when using set-
validator! with a dynamic var?
In a situation like this:
(binding [*my-var* -1]
(foo))
I’d like to be able to throw a custom exception when they try to bind
to a negative number.
Using set-validator! like this, the Exception message is ignored:
(set-validator! #'*d* (fn [x] (if (< x 0) (throw (Exception. "*my-var*
can only be bound to a non-negative number")) true)))
Instead the message you see at the REPL is:
java.lang.IllegalStateException: Invalid reference state
(NO_SOURCE_FILE:0)
Is there a way to specify the error message on validation-error of a
dynamic var?
If you use a RuntimeException instead of an Exception the error mesage will be the message inside of your RuntimeExecption.