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 › Connection error.
Page Index Toggle Pages: 1
Connection error. (Read 801 times)
Connection error.
Dec 4th, 2009, 5:47am
 
I'm running a sketch to grab some data from the interweb once per minute, and stays on for 12 hours at a time. All works fine, UNTIL.. shock horror, my internet drops for a bit - now when the sketch tries to run (and create some strings from the html etc), it cannot find the page, and I get a nullPointer error.

- Im using something like ' if(second()/59 == 1){..}' to tell my sketch to keep looking at the web page, is there some function I can put in a surrounding for() loop or some-such to make it 'try again next minute' if the connection is not found?

Otherwise when I come to check the results after 12 hrs I inevitably find an error from 5 mins into the run-time!

Cheers! W.
Re: Connection error.
Reply #1 - Dec 4th, 2009, 6:07am
 
You need to build in some exception handling.  try/catch might do the trick; though there may just be something built in to the method/library you're using to access the data
Re: Connection error.
Reply #2 - Dec 4th, 2009, 7:51am
 
Ok, well I'm just using a loadStrings() function to load the data, but I'm not really very confident using java, so do you think I could make a 'clunky' fix..something like:

if((second()/59 == 1) && (string = 'not null'){
do web access things
}else if((second()/59 == 1) && (string == null){
println(error-code);
}

- I know this is pretty much what you were pointing out with exception handling, but Im pretty confused just trying to work out what sort of error mine is! - I'm thinking a checked exception?
Re: Connection error.
Reply #3 - Dec 4th, 2009, 8:31am
 
If your Internet connection fails then loadStrings returns null so
Code:

if(second() == 59){
   string = loadStrings("filename");
   if(string != null){
       // process your strings
   }
}

Note that the second() function returns a value 0 - 59 so the above does the same as (second()/59 == 1)

There is no need for exception handling in this case because although an exception is generated when it can't find "filename" this is handled by Processing and loadStrings() returns null instead.
Re: Connection error.
Reply #4 - Dec 5th, 2009, 9:41am
 
Thanks Q, I knew there was an easier way of saying 59 secs. but for some reason I occasionally over complicate the code for my own entertainment it seems!

Ok, perhaps its not losing internet connection thats causing the error then if you dont think that would cause an error! Seems I need to spend some time trying to break it to see how!
Page Index Toggle Pages: 1