I can agree with the multiple-exceptions-in-one-catch, however I don't
think the syntax should be so liberal.  It should all be (catch
[Exception+] e body).

On Nov 28, 1:19 am, "Vijay Lakshminarayanan" <[EMAIL PROTECTED]>
wrote:
> Hi
>
> I'd like to propose a change to Clojure's current try-catch syntax.
>
> Currently the syntax is (copied from clojure.org)
>
> (try expr* catch-clause* finally-clause?)
> catch-clause -> (catch classname name expr*)
> finally-clause -> (finally expr*)
>
> I'd like to propose a change to the catch-clause so that it's possible
> to specify different classnames one of which will be caught and its
> expr evaluated.
>
> It would be something like
>
> (try ...
>   (catch SomeException e (println e))
>   (catch (SomeOtherException OrAnotherException) e
>     (println "xyz" e))
>   (finally ...))
>
> In my programming experience I often find that I need to execute the
> same code for a few different exceptions but specialized code for some
> others and rather than duplicate code (that's why we use lisp right?
> no more code duplication!) I thought it would be best that Clojure
> support the same.
>
> I saw that it wasn't possible to modify the try syntax from Clojure
> itself so I modified the clojure.lang.Compiler file to reflect the
> same.
>
> I produced the diff using "svn diff" so patching the same shouldn't be
> too hard, I think.
>
> With the new syntax Exceptions can be specified in a List, Vector or a
> Set but not a map.  The exceptions must be specified explicitly as
> they will not be evaluated.  So
>
> (try
>  (foo)
>  (catch [InterruptedException MalformedURLException] e (dont (do-what-i-say 
> e)))
>  (catch (ArithmeticException NumberFormatException
> NullPointerException) e (do-what-i-mean e))
>  (catch #{RuntimeException} e)
>  (catch Exception e (println e)))
>
> are all legal.  But
>
> (let [excepts [InterruptedException MalformedURLException]]
>         (try
>          (foo)
>          (catch excepts e (println e))))
>
> will throw an IllegalArgumentException.
>
> Java7 will probably have syntax similar to the 
> abovehttp://tech.puredanger.com/java7#catch
>
> Cheers
> Vijay
>
>  Compiler.java.diff
> 7KViewDownload
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to