catching exception error
Hi clojurians, I was happily clojure-coding whent I tried to catch a exception in a thrown deeply in a function. After looking for the fact that the IllegalArgumentException wasn't catch, I added a catch RuntimeException to my catch list ... and that worked of course. Here is the simplified case: (defn throw-error [arg] (throw (IllegalArgumentException. (str arg (try (let [ test (into {} (map (fn[x] (if (= 5 x) (throw-error x) [x x])) [1 2 3 4 5])) ] (str "NO PB " name)) (catch IllegalArgumentException e (.getMessage e)) (catch RuntimeException e (str "RT" (.getMessage e))) ) If you comment the RuntimeException catch, the exception is not catched. I don't understand why IllegalArgumentException is not catched ... Somebody could tell me ? Thanks Phil --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: catching exception error
The Clojure run time throws IllegalArgumentException in a lot of different places. It does also throw RuntimeException in several places. It traps exceptions generically (catch (Exception e), catch (Throwable t) ) and may have thrown a RuntimeException back to upper layers instead of the original\ IllegalArgumentException. Did you print the RuntimeException ? There might a be a text messages there that can tell us where it came from within the Clojure run time. Luc On Thu, 2009-06-11 at 10:12 -0700, peg wrote: > Hi clojurians, > > I was happily clojure-coding whent I tried to catch a exception in a > thrown deeply in a function. > > After looking for the fact that the IllegalArgumentException wasn't > catch, I added a catch RuntimeException to my catch list ... and that > worked of course. > > Here is the simplified case: > > (defn throw-error [arg] > (throw (IllegalArgumentException. (str arg > > (try > (let [ test > (into {} > (map (fn[x] (if (= 5 x) (throw-error x) [x x])) > [1 2 3 4 5])) ] >(str "NO PB " name)) > (catch IllegalArgumentException e (.getMessage e)) > (catch RuntimeException e (str "RT" (.getMessage e))) > ) > > If you comment the RuntimeException catch, the exception is not > catched. > > I don't understand why IllegalArgumentException is not catched ... > > Somebody could tell me ? > > Thanks > Phil > > > > > > Luc Préfontaine Armageddon was yesterday, today we have a real problem... --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: catching exception error
On Thu, Jun 11, 2009 at 7:12 PM, peg wrote: > > Hi clojurians, > > I was happily clojure-coding whent I tried to catch a exception in a > thrown deeply in a function. > > After looking for the fact that the IllegalArgumentException wasn't > catch, I added a catch RuntimeException to my catch list ... and that > worked of course. Have a look at this thread: http://groups.google.com/group/clojure/browse_thread/thread/b719861006c7e52c/?lnk=gst&q=wrap+RuntimeException -- Michael Wood --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: catching exception error
Thanks for your answers. I read the thread and understood why I don't get my IllegalArgumentException but a new RuntimeException that wrapps it. But I don't understand what the reason is to create a new RuntimeException (stack tracing?) knowing that IllegalException is a subclass of RuntimeException so that it could be thrown directly form clojure core code. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---