> I want to gather some feedback on how others are dealing with the
> issue of pre-conditions raising AssertionError instead of
> IllegalArgumentException, whereas the general practice is to catch

AssertionError and IllegalArgumentException are meant for entirely
different conditions.  That is, you would never use AssertionError to
signal that a user-supplied value does not "look" proper when passed
to a given function.  That is the role of IllegalArgumentException.
You should never allow your code to throw AssertionError -- and by
that I don't mean that you should set! *assert* to false.  If your
code is throwing assertions at runtime, then the next step would be to
go back to the drawing board and assess why that is happening and
eliminate the problem.

Be careful not to mix the idea of function expectations (i.e. pre/
post) and runtime error checking (i.e. exceptions):

(defn convert-user-input-to-keyword [s]
  {:pre  [(string? s) (re-matches #"Billy" s)]
   :post [(keyword? %)]}
  (keyword s))

(convert-user-input-to-keyword "Bobby")
;; AssertionError
;; Yikes!

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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