Loading...
Logo
Processing Forum
Happens usually after about an hour and 12 minutes.

I have no idea how to trap it. Any help would be greatly appeciated

Replies(4)

try / catch doesn't work with loadStrings()...
Check if the returned value is null, instead.
Hi Guys,

Thanks for the suggestions

I have tried it with the following code in my serialEvent() function

Copy code
  1. try
  2. {
  3.                   URL url= new URL(UpdateURL);
  4.                   URLConnection connection = url.openConnection();
  5.                   connection.setRequestProperty("User-Agent", "I am a real browser like Mozilla or MSIE" );
  6.                   String[] results = loadStrings(connection.getInputStream());
  7.                   println(results);
  8. }
  9.                   catch (Exception e)                                                   // MalformedURL, IO
  10. {
  11.                   println("HTTP Error");
  12.                   e.printStackTrace();
  13. }
which works nicely, however I am looking for a more elegant solution. Especially as I am trying to keep this free of imported libraries. So I tried the following which sort of works but doesnt give the expected output

Copy code
  1. String[] result = loadStrings(UpdateURL);
  2. if (result == null);
    {
  3.                   println("Network communications error ");
  4. }

  5. if (result != null);
  6. {
  7.                   println("Server response "+ result[0]);
  8. }
 
For output on every line I get

Network communications error
Server response e.g 2091

I don't understand where I am going wrong. I thought it would just show Network communications error when there was an error and the result of the loadstrings i.e the number when it worked.

But I get both
Stupid me,

did you notice the ; on the end of each if statement!

Sorry :-(