0

I am getting SocketException on following line. I have something like

    try{
        while(){
            doc = Jsoup.connect("http://ampletrails.com").timeout(300000).get();
        } 
    } catch (Exception e) {
e.printStackTrace();
}

Java exception is thrown and program exit. How can I prevent this to continue in while loop and prevent program to exit.

java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:185)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
    at sun.net.www.MeteredStream.read(MeteredStream.java:134)
    at java.io.FilterInputStream.read(FilterInputStream.java:133)
    at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2582)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:273)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
    at org.jsoup.helper.DataUtil.readToByteBuffer(DataUtil.java:113)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:447)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:393)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:159)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:148)
    at base_class.main(base_class.java:20)
Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
Mayank Jain
  • 405
  • 9
  • 19

1 Answers1

0

The exception means that the server is sending a TCP reset to terminate the connection you are making.

If this is an intermittent connection, you could avoid a program exit by putting the try and catch blocks inside the while loop instead of outside. It would be best to figure out why the server is resetting your connections, though.

Warren Dew
  • 8,790
  • 3
  • 30
  • 44