• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Continue after Server returned HTTP response code: 500 for URL

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic