IIRC "catch" is auxiliary syntax---it only has meaning within a (try ...) form.
On Mon, Apr 1, 2013 at 8:21 AM, 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. > > > -- Ben Wolfson "Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure." [Larousse, "Drink" entry] -- -- 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.