# (Simple?) Why is my rescue clause not catching an exception?

**URL:** <https://www.ruby-forum.com/t/simple-why-is-my-rescue-clause-not-catching-an-exception/76721>\
**Category:** Ruby\
**Created:** [November 20, 2006, 6:34pm UTC](https://www.ruby-forum.com/t/simple-why-is-my-rescue-clause-not-catching-an-exception/76721 "2006-11-20T18:34:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [November 20, 2006, 6:34pm UTC](https://www.ruby-forum.com/t/simple-why-is-my-rescue-clause-not-catching-an-exception/76721/1 "2006-11-20T18:34:23Z")

</div>

All,

I’m using the Net::HTTP module to fetch resources from the Internet in a  
Rails application.

I have a method that does the HTTP request and this action is enclosed  
in a begin/rescue/end block. However, when I just did a request and the  
Internet connectivity went down for a second, the call to  
“http.request(req)” failed and I didn’t see my rescue block get  
executed. Instead, it appears that the original exception (from  
timeout.rb) just bubbles all of the way up the stack and my rescue  
doesn’t seem to catch it.

Is this because the call to http.request is inside of it’s own block and  
I would need to place a rescue clause in there?

Here’s the guts of my method:

begin  
if (theURL.instance\_of?(URI::HTTP))  
req = Net::HTTP::Get.new(theURL.request\_uri())  
res = Net::HTTP.start(theURL.host, theURL.port) {|http|  
http.request(req)  
}  
end  
rescue  
raise(“Unable to get page - please check the URL”)  
end

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [November 20, 2006, 6:47pm UTC](https://www.ruby-forum.com/t/simple-why-is-my-rescue-clause-not-catching-an-exception/76721/2 "2006-11-20T18:47:34Z")

</div>

On 20.11.2006 18:34, Wes G. wrote:

> timeout.rb) just bubbles all of the way up the stack and my rescue  
> res = Net::HTTP.start(theURL.host, theURL.port) {|http|  
> http.request(req)  
> }  
> end  
> rescue  
> raise(“Unable to get page - please check the URL”)  
> end
> 
> Thanks,  
> Wes

rescue catches StandardError by default only and the exception thrown by  
Net::HTTP is likely some other type not inheriting standard error.

> > StandardError.ancestors  
> > =\> [StandardError, Exception, Object, Kernel]

You need

rescue Exception

Kind regards

```
robert
```
