I was reading http://blog.fogus.me/2009/12/21/clojures-pre-and-post/
on the new pre and post conditions and seeing that they throw
java.lang.Exception kinda struck me as a bad smell, esp. when
integrating with other systems written in Java or another language.
Forcing upstream clients to catch the top level Exception seems rather
rude on clojures part.
Was there any reason java.lang.Exception was used over say
java.lang.AssertionError? Or a more specific
PreConditionAssertionError/PostConditionAssertionError pair?
Mark
--
Pull me down under...
On Dec 23, 5:03 pm, Mark Derricutt <m...@talios.com> wrote:
> 'lo,
>
> I was readinghttp://blog.fogus.me/2009/12/21/clojures-pre-and-post/
I've written a related patch that makes three changes:
1. assert now raises AssertionError, instead of Exception.
2. assert is now overloaded with a second parameter that replaces
"Assert failed" in the original message.
3. the (pre- or post-) condition that raised the exception, along with
the form responsible, is now reported.
Previously:
"Caused by: java.lang.Exception: Assert failed: (= % x)"
Now:
"Caused by: java.lang.AssertionError: Postcondition failed when (bad-
fn 2): (= % x)"
Assembla seems to be having some problems, so I'm hosting it at
http://fanatico.org/better-pre-post.diff until they get that sorted
out.
Thoughts?
With your patch, assert does not include x in its message anymore in
case s is not given. Also, as a non-native speaker I find the phrase
"failed when" somewhat strange to my ears. Aside from this, your patch
immediately makes clear what went wrong.
Forcing is the problem of Java's checked exceptions. Without them,
there would never be forcing.
> Was there any reason java.lang.Exception was used over say
> java.lang.AssertionError? Or a more specific
> PreConditionAssertionError/PostConditionAssertionError pair?
>
But yes, java.lang.AssertionError is a better fit and I've changed
assert to throw that.
Rich