On Mon, May 18, 2009 at 4:38 PM, samppi <rbysam...@gmail.com> wrote: > > I want to create a function that takes a variable of an error-kit > error type and inserts it into a handle statement, but when I try, I > get a strange error. What does the error mean, and is there a way to > pass a variable error type into a handle statement without resorting > to macros? > > Clojure 1.0.0- > user=> (use 'clojure.contrib.error-kit) > nil > user=> (deferror parse-error [] [] > {:msg "WHEEE", :unhandled (throw-msg IllegalArgumentException)}) > #'user/parse-error > user=> (defn a [error-type] > (with-handler > (raise parse-error) > (handle error-type [x] x))) > java.lang.RuntimeException: java.lang.RuntimeException: > java.lang.RuntimeException: java.lang.Exception: Assert failed: v > (NO_SOURCE_FILE:13)
When used this way, the first arg to 'handle' must be a literal argument type name, not a local that contains something. However, you can actually match on whatever you want (see the "The above is equivalent..." example in the .clj): (defn a [error-type] (with-handler (raise parse-error) (handle {tag :tag :as this-err} (if (isa? tag error-type) (prn :caught this-err) (do-not-handle))))) --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---