We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › when loadstrings(url) fails
Page Index Toggle Pages: 1
when loadstrings(url) fails (Read 856 times)
when loadstrings(url) fails
Mar 22nd, 2007, 10:27am
 
Hello!

My sketch every minute fetches a page from the web. after about eleven hours loadstrings failed with below stack trace. Am I right to wrap the loadstrings in a try, and catch NullPointerException to just return from the function to have the sketch survive the condition? (the compiler wont let me catch IOException.)

Please advise.

Peter

Stack trace:
java.io.IOException: Premature EOF
       at sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:538)
       at sun.net.www.http.ChunkedInputStream.readAhead(ChunkedInputStream.java:582)
       at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:669)
       at java.io.FilterInputStream.read(FilterInputStream.java:111)
       at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:408)
       at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:450)
       at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:182)
       at java.io.InputStreamReader.read(InputStreamReader.java:167)
       at java.io.BufferedReader.fill(BufferedReader.java:136)
       at java.io.BufferedReader.readLine(BufferedReader.java:299)
       at java.io.BufferedReader.readLine(BufferedReader.java:362)
       at processing.core.PApplet.loadStrings(PApplet.java:4290)
       at processing.core.PApplet.loadStrings(PApplet.java:4272)
       at cafebot$logReader.readServer(cafebot.java:140)
       at cafebot$logReader.run(cafebot.java:157)
       at java.lang.Thread.run(Thread.java:534)
java.lang.NullPointerException
       at cafebot$logReader.readServer(cafebot.java:141)
       at cafebot$logReader.run(cafebot.java:157)
       at java.lang.Thread.run(Thread.java:534)

Re: when loadstrings(url) fails
Reply #1 - Mar 22nd, 2007, 12:16pm
 
Hello!

One hour later, the sketch again failed on the same condition. Catching the nullpointer did not help. I guess the ioexception somewhere down in processing has to be caught instead. I will try and file a bug report.

Thank you.

Peter
Re: when loadstrings(url) fails
Reply #2 - Mar 22nd, 2007, 12:45pm
 
Ahh,

from reading the PApplet source I get, the first (IOException) trace is there deliberately. I will now check whether loadstrings() returns null Smiley

Hope that fixes that! If it works out right, I suggest to add  to the docs that on error ls returns null, though I did not read those eiter...

Sorry for the noise!

Peter
Re: when loadstrings(url) fails
Reply #3 - Mar 22nd, 2007, 1:12pm
 
OK,

checking for "null" return of loadstrings keeps the sketch alive! Now, why would the IO error happen at all (the requested page always has something to show)?

Thank you.

Peter
Re: when loadstrings(url) fails
Reply #4 - Mar 23rd, 2007, 12:58pm
 
it prints the error so that you know the nature of the error that happened, which is usually helpful in debugging. normally, you'd have to put this inside a try/catch block, but that's a bit much for most users, who usually just want to know whether the data came through or not.
Re: when loadstrings(url) fails
Reply #5 - Mar 23rd, 2007, 6:34pm
 
I was confused, as the processing message looked exactly like in java an uncaught exception does.

Peter
Page Index Toggle Pages: 1