I am using this code to retreive a html page and parse it
while(doc == null && retry<5){
retry++;
try {
doc = Jsoup.connect(url).get();
} catch (IOException e) {
Log.e("ReleaseInfo", "JSoup get didnt get a document", e);
}
Once the doc is retrieved i am using this to get some information and testing for nullness.
overview = doc.select("div#object-overview").last();
if(overview != null){
paragraph = overview.select("p").last();
if(paragraph != null){
Log.v("Paragraph", paragraph.text());
}else{
Toast.makeText(releaseInfo.this, "No over view content", Toast.LENGTH_SHORT);
}
}
else{
}
featureList = doc.select("div.callout-box").last();
if(featureList != null){
Log.v("OverView", featureList.text());
As you see i am catching the error with a log statement. The IOException is telling me this
08-17 12:54:11.535: ERROR/ReleaseInfo(5960): JSoup get didnt get a document
08-17 12:54:11.535: ERROR/ReleaseInfo(5960): java.net.SocketTimeoutException
08-17 12:54:11.535: ERROR/ReleaseInfo(5960): at org.apache.harmony.luni.net.PlainSocketImpl.read(PlainSocketImpl.java:564)
08-17 12:54:11.535: ERROR/ReleaseInfo(5960): at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:88)
08-17 12:54:11.535: ERROR/ReleaseInfo(5960): at java.io.InputStream.skip(InputStream.java:258)
08-17 12:54:11.535: ERROR/ReleaseInfo(5960): at org.apache.harmony.luni.net.SocketInputStream.skip(SocketInputStream.java:93)
08-17 12:54:11.535: ERROR/ReleaseInfo(5960): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl$ChunkedInputStream.skipOutstandingChunks(HttpURLConnectionImpl.java:374)
How could i make my code defensive against this error to not force close when the document isnt retreived?
Also i would like to catch and respond to this exception that causes my application to force close.
08-17 16:27:29.245: ERROR/ReleaseInfo(8641): JSoup get didnt get a document
08-17 16:27:29.245: ERROR/ReleaseInfo(8641): java.io.IOException: 404 error loading URL http://pc.gamespy.com/web-games/parking-wars-2/
08-17 16:27:29.245: ERROR/ReleaseInfo(8641): at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:387)
08-17 16:27:29.245: ERROR/ReleaseInfo(8641): at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:364)
08-17 16:27:29.245: ERROR/ReleaseInfo(8641): at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:143)
08-17 16:27:29.245: ERROR/ReleaseInfo(8641): at org.jsoup.helper.HttpConnection.get(HttpConnection.java:132)