Hey Bill. I am guessing the problem is that the rethrow macro is expanded and passed to the reader/compiler before the handle-ex macro is. And at that point the compiler sees catch as a "standalone-symbol", not as part of the try special form. Macro-experts, please correct me :)
Tried to quickly catch up with http://www.infoq.com/presentations/Clojure-Macros, but infoq seems slow. Cheers, Alf On 1 April 2013 17:21, Bill Robertson <billrobertso...@gmail.com> wrote: > I was all excited when I was able to consolidate a lot of try/catch logic > behind a macro earlier this morning. All was good. > > I felt like I could do a better job of communicating my intentions in the > code though with a rethrow construct rather than writing > (catch FooException #f (throw #f)) > > I would have liked to have been able to simply write > (rethrow FooException) > > This failed. Poking around the docs a bit, I see that try/catch is a > special form. Which makes sense. > > user=> (defmacro rethrow [ex-class] `(catch ~ex-class x# (throw x#))) > #'user/rethrow > user=> (defmacro handle-ex [message & body] `(try ~@body (rethrow > IllegalArgumentException) (catch Exception x# (throw > (IllegalArgumentException. message))))) > #'user/handle-ex > user=> (handle-ex "no" (throw (IllegalArgumentException. "yes"))) > CompilerException java.lang.RuntimeException: Unable to resolve symbol: > catch in this context, compiling:(NO_SOURCE_PATH:1:1) > > It was a longshot, but I tried to qualify catch. That fails too, because > it's not really there... > > user=> (defmacro rethrow [ex-class] `(clojure.core/catch ~ex-class x# > (throw x#))) > #'user/rethrow > user=> (defmacro handle-ex [message & body] `(try ~@body (rethrow > IllegalArgumentException) (catch Exception x# (throw > (IllegalArgumentException. message))))) > #'user/handle-ex > user=> (handle-ex "no" (throw (IllegalArgumentException. "yes"))) > CompilerException java.lang.RuntimeException: No such var: > clojure.core/catch, compiling:(NO_SOURCE_PATH:1:1) > > Is this possible to do within the normal bounds of the language? > > Thanks! > > > -- > -- > 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/groups/opt_out. > > > -- -- 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/groups/opt_out.