# Can't rescue this (http-access2)

**URL:** <https://www.ruby-forum.com/t/cant-rescue-this-http-access2/53097>\
**Category:** Ruby\
**Created:** [January 25, 2006, 5:47am UTC](https://www.ruby-forum.com/t/cant-rescue-this-http-access2/53097 "2006-01-25T05:47:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Horacio\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@Horacio\_S](https://www.ruby-forum.com/u/Horacio_S)\
**Post date:** [January 25, 2006, 5:47am UTC](https://www.ruby-forum.com/t/cant-rescue-this-http-access2/53097/1 "2006-01-25T05:47:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Horacio\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@Horacio\_S](https://www.ruby-forum.com/u/Horacio_S)\
**Post date:** [January 26, 2006, 8:55pm UTC](https://www.ruby-forum.com/t/cant-rescue-this-http-access2/53097/2 "2006-01-26T20:55:48Z")

</div>

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.
