From: Nigel Gilbert Date: 2003-07-05T05:58:37+09:00 Subject: The best way to catch errors My ruby program processes web pages, which it collects using the methods in net/http. Every now and again, it tries to access a web page which is no longer available, is protected with a password, is on a slow server that yields a timeout, and so on. What I'd like to do, therefore, is protect the page fetching method with a begin...rescue..end construction that will cause the program simply to move on to the next web page that needs to be fetched if there is an access error. However, I don't want to trap any other kinds of error (e.g. I'd still like to be able to interrupt the program with ^C). Now, the obvious way of doing this is to append exception classes for all the different types of web access error to the rescue clause, thus: rescue ProtocolError, ProtoSyntaxError, ..., TimeoutError => e where ... represents all the other possible errors. As far as I can see, however, there are two problems with this. The first is that ProtocolError (etc.) is defined in net/protocol.rb, which is 'required' by 'net/http', which in turn is required by my program. The consequence is that my program has no knowledge of ProtocolError and the compiler objects that it is an uninitialized constant. The second problem is that I don't know how to construct a complete list of all the different types of exception that I should include in my rescue clause. I've already discovered relevant exceptions defined in http.rb, protocol.rb and timeout.rb, but there may be more. How can I find a list of all the exceptions that could occur? Nigel