cant catch a simple exception

55 views
Skip to first unread message

gavvyth...@gmail.com

unread,
Mar 28, 2014, 7:27:31 AM3/28/14
to codenameone...@googlegroups.com
I am testing the following code

try{
                
                    JSONParser p = new JSONParser();
                    Map<String, Object> h = p.parseJSON(new InputStreamReader(input));
            
                }
                
                catch(java.lang.ArrayIndexOutOfBoundsException e)
                {
                    System.out.println("Error : " + e.getMessage());
                    return;
                }
the parseJSON() call throws an exception ArrayIndexOutofBounds under some circumstances but I cant catch it! Can anyone advise

Th3B1gBull

unread,
Mar 28, 2014, 10:44:01 AM3/28/14
to codenameone...@googlegroups.com, gavvyth...@gmail.com
maybe you'r trying to catch the wrong exception.
ArrayIndexOutOfboBoundsException should be a subcluss of IndexOutofBoundException... try it with catch Exception and look if it works.
Greets

gavvyth...@gmail.com

unread,
Mar 28, 2014, 12:08:13 PM3/28/14
to codenameone...@googlegroups.com, gavvyth...@gmail.com

gavvyth...@gmail.com

unread,
Mar 28, 2014, 12:08:59 PM3/28/14
to codenameone...@googlegroups.com, gavvyth...@gmail.com
thanks for the suggestion but no that does not work either

Steve Hannah

unread,
Mar 28, 2014, 12:18:39 PM3/28/14
to codenameone...@googlegroups.com, gavvyth...@gmail.com
Is this on the device or in the simulator?  If device, which device?

Steve


--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/23c8dc53-55f1-4385-b109-ea6fb808b1c4%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Web Lite Solutions Corp.

gavvyth...@gmail.com

unread,
Mar 28, 2014, 12:22:00 PM3/28/14
to codenameone...@googlegroups.com, gavvyth...@gmail.com
Its on the simulator. I think I have had enough of codeneme one to be honest , its a great idea and I m sure it will be an awesome product but really its a long way off in my opinion...


Steve Hannah

unread,
Mar 28, 2014, 12:44:32 PM3/28/14
to codenameone...@googlegroups.com, gavvyth...@gmail.com
On Fri, Mar 28, 2014 at 9:22 AM, <gavvyth...@gmail.com> wrote:
Its on the simulator. I think I have had enough of codeneme one to be honest , its a great idea and I m sure it will be an awesome product but really its a long way off in my opinion...

This is quite a leap based on just not being able to catch an exception.  If you're running in the simulator, then it's just running on your machines JVM and you're dealing in pure Java.  So if you can't catch an exception, then it's really either that you're doing it wrong or there's a JVM bug.  I wouldn't bet against the JVM on this one.

Do you have a stack trace?

Steve
 


--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.

For more options, visit https://groups.google.com/d/optout.

Steve Hannah

unread,
Mar 28, 2014, 1:17:50 PM3/28/14
to codenameone...@googlegroups.com
Forgot to post this reply to the list.

Steve

---------- Forwarded message ----------
From: Steve Hannah <st...@weblite.ca>
Date: Fri, Mar 28, 2014 at 10:17 AM
Subject: Re: [codenameone-discussions] Re: cant catch a simple exception
To: gavin Stevens <gavvyth...@gmail.com>


Try putting a print statement just after the parseJSON() call. e.g.

 Map<String, Object> h = p.parseJSON(new InputStreamReader(input));
Log.p("We are here");


My prediction, is that the code will reach your "We are here" print statement.  I suspect that JSONParser is catching the ArrayIndexOutOfBoundsException and printing the stack trace and not propagating it up.  That's why you can't catch the exception.  Because no exception  is actually being raised by parseJSON.  Does that make sense to you?

Ultimately, you'll want to look at the JSON code that you are parsing to see why the parser is choking on it. 

Steve



On Fri, Mar 28, 2014 at 9:59 AM, gavin Stevens <gavvyth...@gmail.com> wrote:
java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.get(ArrayList.java:324)
at com.codename1.io.JSONParser.isStackHash(JSONParser.java:365)
at com.codename1.io.JSONParser.stringToken(JSONParser.java:443)
at com.codename1.io.JSONParser.parse(JSONParser.java:119)
at com.codename1.io.JSONParser.parseJSON(JSONParser.java:343)
at userclasses.StateMachine$1.readResponse(StateMachine.java:61)
at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:401)
at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:261)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
Reply all
Reply to author
Forward
0 new messages