Can't rescue this (http-access2)

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:in
`parse_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:in `timeout'
        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:in
`read_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:in
`do_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:in `start'
        from ./scrapper.rb:984:in `each'
        from ./scrapper.rb:984:in `start'
        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

Horacio Sanson wrote:

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:in
`parse_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:in `timeout'
        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:in
`read_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:in
`do_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:in `start'
        from ./scrapper.rb:984:in `each'
        from ./scrapper.rb:984:in `start'
        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??

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.