smartly handle "java.net.connectException: connection timed out" error?

Hi, I have written a program to periodly check a web site to read some information periodly (use Timer). The code is posted below.

The problem is: when the "connection timed out" exception happens, the program seems stopped to execute at next desired time (after 10min) but did not quit either... (There was two "connection timed out" error)

Can you tell me what happended there and how should I correct the code make it handle this network exception more smartly? I don't want to code to quit, I want it just ignore the error (since sometimes network is not stable) and continually run at next desired time...

Thanks for your attention!

Mike

publicvoid readHTML(){

try{

URL url =new URL("http://www.cnn.com");

BufferedReader in =new BufferedReader(new InputStreamReader(url.openStream()));

String str;

while ((str = in.readLine()) !=null){

//process str.....

//if wanted info is read, process it and return

return;

}

}

}catch (MalformedURLException e){

e.printStackTrace();

}catch (IOException e){

e.printStackTrace();

}

}

publicvoid monitor(){

Timer timer =new Timer();

timer.schedule(new RemindTask(), 0, interval*1000);

}

class RemindTaskextends TimerTask{

publicvoid run(){

readHTML();

}

}

[2557 byte] By [happyhelpera] at [2007-10-2 2:23:35]
# 1

ConnectionException is an IOException.

In your code you have the following code which prints the stack trace.

} catch (IOException e) {

e.printStackTrace();

If you want to ignore ConnectionExceptions I suggest you add a catch block.

} catch (ConnectionException ignored) {

// ignored

} catch (IOException e) {

e.printStackTrace();

Peter-Lawreya at 2007-7-15 20:15:03 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
Peter, I just found out that it was because of another changing of the code instead of exception catching.. but thanks for the reply and dd is rewarded :-).
happyhelpera at 2007-7-15 20:15:03 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3
Hi >I just found out that it was because of another changing of the code >instead of exception catchingWhat did you change please let me know . I am also facing this type of problem. ThanksBharathi
VedBharathia at 2007-7-15 20:15:03 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...