How I can catch exception from cheshire.core?

351 views
Skip to first unread message

Алексей Александров

unread,
Sep 11, 2013, 4:56:29 AM9/11/13
to clo...@googlegroups.com
Hello.

I'm trying catch exception from cheshire.core/decode (or parse-string). But it didn't work

user=> (require ['cheshire.core :as 'json])
user=> (try (json/decode "[{\"id\":ty\":1}]") (catch Throwable _ (println "I catched exception")))
JsonParseException Unrecognized token 'ty': was expecting 
 at [Source: java.io.StringReader@1fd2f14; line: 1, column: 10]  com.fasterxml.jackson.core.JsonParser._constructError (JsonParser.java:1369)

com.fasterxml.jackson.core.JsonParser._constructError is helper method for constucting JsonParseException object
called like:
throw _constructError("Numeric value ("+getText()+") out of range of Java byte")

--
Alexey Aleksandrov

Cedric Greevey

unread,
Sep 11, 2013, 5:17:10 AM9/11/13
to clo...@googlegroups.com
Is json/decode returning a lazy seq? If so, you're constructing it inside the try and then realizing it outside the try, and the exception may be coming from the realization step.


--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Алексей Александров

unread,
Sep 11, 2013, 6:29:39 AM9/11/13
to clo...@googlegroups.com
Yes, json/decode return clojure.lang.LazySeq.
I added (doall  ) to force calculation.

Thank you.



2013/9/11 Cedric Greevey <cgre...@gmail.com>



--
Alexey Aleksandrov

Norman Richards

unread,
Sep 11, 2013, 12:55:29 PM9/11/13
to clo...@googlegroups.com


On Wednesday, September 11, 2013 5:29:39 AM UTC-5, Алексей Александров wrote:
Yes, json/decode return clojure.lang.LazySeq.
I added (doall  ) to force calculation.

This bit me on a project yesterday.   I also added a doall, but I haven't had time to investigate whether any of the interior items are also lazy, in which case I guess we'd need some sort of tree walking doall?   
Reply all
Reply to author
Forward
0 new messages