Forum: Ruby Can't rescue this (http-access2)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
81cf8dab4b4af8aa3148c28421afd845?d=identicon&s=25 Horacio Sanson (Guest)
on 2006-01-25 05:47
(Received via mailing list)
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
428f96cc689eb7419bba3a8bbfcc222a?d=identicon&s=25 Stefan Mahlitz (Guest)
on 2006-01-26 20:55
(Received via mailing list)
Horacio Sanson 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.
This topic is locked and can not be replied to.