`catch` is not a function or macro, it's special syntax only understood in the context of the special form `try`. You can't do this without writing your own form of try (see try+ in slingshot <https://github.com/scgilardi/slingshot> for an example of that).
On Wednesday, December 20, 2017 at 9:53:40 AM UTC-6, cris...@procrustes.net wrote: > > How do I use catch and throw in a macro? > > Here's a summary in the repl of what I have tried: > > user=> (defmacro catch2 [class bind-var & body] `(catch ~class ~bind-var > ~@body)) > #'user/catch2 > user=> (macroexpand-1 '(catch2 Exception e nil)) > (catch Exception e nil) > user=> (try nil (catch2 Exception e nil)) > > CompilerException java.lang.RuntimeException: Unable to resolve symbol: > catch in this context, > compiling:(/tmp/form-init7515078331866806804.clj:1:10) > > > Trying with explicit namespace on the catch: > > user=> (defmacro catch2 [class bind-var & body] `(clojure.core/catch > ~class ~bind-var ~@body)) > #'user/catch2 > user=> (macroexpand-1 '(catch2 Exception e nil)) > (clojure.core/catch Exception e nil) > user=> (try nil (catch2 Exception e nil)) > > CompilerException java.lang.RuntimeException: No such var: > clojure.core/catch, compiling:(/tmp/form-init7515078331866806804.clj:1:10) > > > I have tried with clojure 1.8.0 and 1.9.0. Both have the same outcome. Can > someone please point me to what I am doing wrong here, please? > > Thankyou > > Crispin > -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.