On Mon, Jan 24, 2011 at 4:54 PM, Shantanu Kumar <kumar.shant...@gmail.com> wrote: > > > On Jan 25, 2:47 am, Aaron Cohen <aa...@assonance.org> wrote: >> On Mon, Jan 24, 2011 at 2:27 PM, Shantanu Kumar >> >> <kumar.shant...@gmail.com> wrote: >> > I noticed that in 'with-open' macro the .close() method is called >> > without wrapping in another try-catch block. Exceptions raised in the >> > finally block prevails over the exception raised in the try block. Is >> > this intended behavior or I am missing something? >> >> > Is there an alternative where the exceptions raised due to >> > invoking .close() can be ignored? >> >> Why not do: >> >> (with-open [reader (Reader.)] >> (try >> ... >> (catch) >> ) >> >> Rather than putting the try outside the with-open? > > That won't solve it because .close() works at 'with-open' level and > overrides (when it raises an exception) the body of code I pass to the > 'with-open' macro. You can verify this with Ken Wesson's code example > in this thread. >
I'm not quite sure, but this seems more like a bug or limitation in try/catch to me: ; Defining Doable, Closeable and Foo the same was as Ken did earlier in this thread user=> (pprint (macroexpand-all '(with-open [x (Foo.)] (try (doit x) (catch Exception e (.getMessage e)))))) (let* [x (new Foo)] (try (do (try (doit x) (catch Exception e (. e getMessage)))) (finally (. x clojure.core/close)))) nil The inner exception to me should clearly be caught and not rethrown. So I would really expect to see two printouts when this is run, once for doit and once for close. Why would the finally block of an outer try statement be called when an inner try has already caught the exception? (Also, why is the close in the finally block saying "clojure.core/close" when I macroexpand?) -- 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