Skip to content

Instantly share code, notes, and snippets.

@candera
Created July 28, 2010 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save candera/495545 to your computer and use it in GitHub Desktop.
Save candera/495545 to your computer and use it in GitHub Desktop.
(defn nfe-test []
(try
(let [nums (map #(Integer/parseInt %) ["1" "2" "1234123412341234"])]
(when (every? #(< 3 %) nums)
nums))
(catch NumberFormatException nfe nil)))
(nfe-test) ;; throws NumberFormatException, but I would expect it to
;; return nil
@fogus
Copy link

fogus commented Jul 28, 2010

(defn nfe-test []
  (try
    (let [nums (map #(Integer/parseInt %) ["1" "2" "1234123412341234"])]
      (when (every? #(< 3 %) nums)
    nums))
    (catch NumberFormatException nfe 42)
    (catch RuntimeException nfe nil)))

(nfe-test)

@fogus
Copy link

fogus commented Jul 28, 2010

(defn nfe-test []
  (try
   (let [nums [(Integer/parseInt "1") (Integer/parseInt "2") (Integer/parseInt "1234123412341234")]]
     (when (every? #(< 3 %) (doall nums))
       nums))
   (catch NumberFormatException nfe 42)
   (catch RuntimeException nfe nil)))

(nfe-test)

lazy seq screws that exception up.

@candera
Copy link
Author

candera commented Aug 8, 2010

Yeah, someone on IRC helped me figure that out. It's highly non-obvious, although it makes sense once I understood it. And it also drives home why checked exceptions totally suck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment