Can't rescue this (http-access2)


#1

I have a code like this

def connect(redirect=3)

# Do we have a url to process do we?? if not simply return
if not @uri
    return nil
end

begin
   @clnt = HTTPAccess2::Client.new()
   @clnt.set_cookie_store("cookie.dat")
   @resp = @clnt.get(@uri)
   @code = @resp.status.to_s
   @message = @resp.reason
 rescue SocketError
    @code = "404"
    @message = "Not Found"
rescue Exception => e
     puts "#{self.class} Exception connecting to #{@uri.to_s} : 

#{e.to_s}"
@code = “408”
@message = e.to_s
end

@resp
end

this works as expected but some times (not always) I get an error and
the
scripts bails out.

c:/ruby/lib/ruby/site_ruby/1.8/http-access2.rb:1466:in gets': Invalid argument (Errno::EINVAL) from c:/ruby/lib/ruby/site_ruby/1.8/http-access2.rb:1466:inparse_header’
from c:/ruby/lib/ruby/site_ruby/1.8/http-access2.rb:1464:in
timeout' from c:/ruby/lib/ruby/1.8/timeout.rb:55:intimeout’
from c:/ruby/lib/ruby/site_ruby/1.8/http-access2.rb:1464:in
parse_header' from c:/ruby/lib/ruby/site_ruby/1.8/http-access2.rb:1422:inread_header’
from c:/ruby/lib/ruby/site_ruby/1.8/http-access2.rb:1254:in
get_status' from c:/ruby/lib/ruby/site_ruby/1.8/http-access2.rb:466:indo_get_header’
from c:/ruby/lib/ruby/site_ruby/1.8/http-access2.rb:436:in
do_get_block' ... 6 levels... from ./scrapper.rb:1000:instart’
from ./scrapper.rb:984:in each' from ./scrapper.rb:984:instart’
from main.rb:208

I think I am rescuing all possible things that could go wrong here so my
script should continue ignoring this error but the scripts stops.

How can I rescue this??

regards
Horacio


#2

Horacio S. wrote:

begin
    @code = "408"

    from c:/ruby/lib/ruby/site_ruby/1.8/http-access2.rb:1254:in 

I think I am rescuing all possible things that could go wrong here so my
script should continue ignoring this error but the scripts stops.

How can I rescue this??

a simple

rescue => e

should work as Errno is derived from SystemCallError (which inherits
from StandardError).

See Pickaxe II page 108 for details.

Actually I don’t know why catching Exception doesn’t work.