| Author |
Continue after Server returned HTTP response code: 500 for URL
|
Mark Nicholas
Greenhorn
Joined: Jul 22, 2002
Posts: 13
|
|
This is probably a more low level error handle question: The following code is used to get the contents of multiple url's, however when the server returns a 500 response code the program exits: So my question is how do you contine / handle the 500 exception more gracefully ? java.io.IOException: Server returned HTTP response code: 500 for URL: http://www.some.url at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:691) at java.net.URL.openStream(URL.java:955) at com.jm.utils.UrlReader.<init>(UrlReader.java:36) at com.jm.prj.webgrab.ex01.WebGrabEX01.grab(WebGrabEX01.java:42) at com.jm.prj.webgrab.ex01.WebGrabEX01.main(WebGrabEX01.java:29) [ October 08, 2002: Message edited by: Mark Nicholas ] [ October 08, 2002: Message edited by: Mark Nicholas ] [ October 08, 2002: Message edited by: Mark Nicholas ]
|
 |
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
|
|
What is ungraceful about the way it works? When an error occurs, an exception is thrown. This is entirely as it should be In your case, you can catch the exception within the hosts loop, log it, and continue with the next iteration (and a fresh URL object). - Peter
|
 |
Mark Nicholas
Greenhorn
Joined: Jul 22, 2002
Posts: 13
|
|
Actually it hangs because when the server throws a 500 the 'is' stream variable is null and I forgot to wrap the is.close() with a checking if is != null. Otherwise your right on the money. Thanks
|
 |
 |
|
|
subject: Continue after Server returned HTTP response code: 500 for URL
|
|
|