I finally came up with a simple example which shows the broken
exception handling behavior I described in my earlier post on this
thread.
(defn broken-catch [filename]
(try (java.io.FileReader. filename)
(catch java.io.FileNotFoundException fnfe
"FileNotFoundException caught")
(catch RuntimeException ioe
(str "RuntimeException caught; cause: "
(.getCause ioe)))))
user=> (broken-catch "/etc/passwdXYZ")
"RuntimeException caught; cause: java.io.FileNotFoundException: /etc/
passwdXYZ (No such file or directory)"
The FileReader constructor throws a FileNotFoundException when the
file specified by the argument does not exist:
http://download.oracle.com/javase/6/docs/api/java/io/FileReader.html#FileReader(java.lang.String)
— and as you can see here, Clojure 1.3.0 wrapped it in a
RuntimeException, so the expected typed catch does not work.
However, if invoked in a way which bypasses reflection, the exception
is properly typed:
user=> (try (java.io.FileReader. "/etc/passwdXYZ")
(catch java.io.FileNotFoundException fnfe
"FileNotFoundException caught")
(catch RuntimeException ioe
(str "RuntimeException caught; cause: "
(.getCause ioe))))
"FileNotFoundException caught"
--
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