How to handle JsonParseException ?

150 views
Skip to first unread message

Vivek Jha

unread,
Mar 11, 2014, 2:06:30 PM3/11/14
to googl...@googlegroups.com
In my code I used to directly parse json responses which I got from my server and handled different IOexceptions like Socketexception; sockettimeoutexception to show different messages to users.

But now I find that I no longer get these exceptions and instead get JSONSyntaxException in all these cases when I do gson.fromjson. Is there a way to extract the inner Ioexceptions  from this so that I can handle it the same way I used to do earlier.

I have one more doubt about the reasoning behind throwing JsonSyntaxException in case of these IOExceptions. Why can't gson have thrown JsonIOException instaed?

Inderjeet Singh

unread,
Mar 11, 2014, 2:14:37 PM3/11/14
to googl...@googlegroups.com
These should be JsonIOExceptions instead of JsonSyntaxException. Please log a bug (ideally with a testcase).
What is probably happening is that the socket errors are causing the stream to end prematurely, and Gson sees incomplete JSON and treats that as a syntax error.

HTH
Inder
----
 

Vivek Jha

unread,
Mar 11, 2014, 2:53:59 PM3/11/14
to googl...@googlegroups.com
Ok,
will do that.

But for now will using getCause help? Will it return the top level throwable which maybe I can cast to IOException?

Inderjeet Singh

unread,
Mar 18, 2014, 3:52:13 AM3/18/14
to googl...@googlegroups.com
I think the cause will contain the IOException, but you can debug and find out. :)

Vivek Jha

unread,
Mar 18, 2014, 4:21:31 AM3/18/14
to googl...@googlegroups.com
Thanks,

I am doing this currently.
Reply all
Reply to author
Forward
0 new messages