Dealing with timeouts
in
Programming Questions
•
2 years ago
I'm doing stuff with xml, pulling it from a web site which sometimes takes its time to respond. As a result, I frequently get
- java.net.ConnectException: Connection timed out: connect
in my code, inevitably followed by a NullPointerException, leading the whole program to fail because the server was a bit slow. How should I be dealing with this? Is it a terrible idea to try and catch the exception, and just run the method again if it throws one? Like, in getNodeId I have
- try {
- xml = new XMLElement(this, "http://everything2.com/title/"+title+"?displaytype=softlinks");
- }
- catch(Exception e) {
- println("Exception in getNodeId: "+e);
- return getNodeId(title);
- }
It's been years since I worked on anything big or faily enough to really need try/catch, so I feel like I may be forgetting some subtleties and possibly doing the whole thing wrong anyway... can anyone give me any pointers here?
1