Hi,
Am Mittwoch, 19. Juni 2013 17:00:17 UTC+2 schrieb Max Gonzih:
>
> Hi, I implemented small macro to catch multiple exception classes with one
> body.
>
> https://gist.github.com/Gonzih/5814945
>
> What do you think? Are there better ways to achieve similar results?
>
>
I would just extend try a simply as possible: simply add the catch-all, but
keep catch and finally as is. Here my try:
(defmacro try*
[& body]
(let [catch-all? #(and (seq? %) (= (first %) 'catch-all))
expand-catch (fn [[_catch-all exceptions & catch-tail]]
(map #(list* 'catch % catch-tail) exceptions))
transform (fn [form]
(if (catch-all? form)
(expand-catch form)
[form]))]
(cons `try (mapcat transform body))))
(try*
(println :a)
(println :b)
(catch-all [A B C] e (println (type e)))
(catch D _ (println "Got D!"))
(finally (println "Finally!")))
expands to
(try
(println :a)
(println :b)
(catch A e (println (type e)))
(catch B e (println (type e)))
(catch C e (println (type e)))
(catch D _ (println "Got D!"))
(finally (println "Finally!")))
Kind regards
Meikel
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.