Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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)
share|improve this question
    
This answer might apply, please take a look. –  Bhesh Gurung May 4 at 4:08
    
How can I prevent termination of this program? –  Mayank Jain May 4 at 4:15

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.