oops gensym mistake!
(defmacro capture-inputs [f & args]
`(try (apply ~f ~@args)
(catch Exception e# (do (println "oops!") {:e e# :inputs (vec
~args)}))))
Jim
On 04/09/12 12:20, Jim - FooBar(); wrote:
you want the exception thrown to report the arguments or 'capture
them' (as you say) in the actual Exception object so you can use them
outside the try-catch scope? the former is very straight forward you
just use your arguments...the latter is more fuss as you have to
gen-class your own exception type and and pass the arguments to its
constructor so they can be stored internally...at least this is what i
understand from your question...
Jim
p.s: I just realised you can simply return a map
(defn foo [x y]
(try (doSomething x y)
(catch Exception e {:e e :inputs [x y]}))) ;;return the map
(defmacro capture-inputs [f & args]
`(try (apply ~f ~@args)
(catch Exception e (do (println "oops!") {:e e :inputs (vec ~args)}))))
On 04/09/12 05:03, Timothy Pratley wrote:
I'm working on a project where it would be quite convenient to have
the input values to the function reported in any exceptions that get
thrown. I'm guessing the way to do this would be to create a
replacement defn which had a try catch and threw a new error with the
inputs captured. Has anyone tried this, know of a better way, or a
library that helps in this way? --
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
--
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