# Dynamic requires

**URL:** <https://www.ruby-forum.com/t/dynamic-requires/119144>\
**Category:** Ruby\
**Created:** [November 3, 2007, 7:37pm UTC](https://www.ruby-forum.com/t/dynamic-requires/119144 "2007-11-03T19:37:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 3, 2007, 7:37pm UTC](https://www.ruby-forum.com/t/dynamic-requires/119144/1 "2007-11-03T19:37:37Z")

</div>

I don’t want to go into to much boring detail as to why I am trying to  
do  
this… but why doesn’t this work?

begin  
require ‘foo’  
rescue  
class Foo  
end  
end

Instead of rescuing the error (when ‘foo’ is not found), it still gets  
thrown.

regards,  
Matt

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 3, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/dynamic-requires/119144/2 "2007-11-03T19:49:54Z")

</div>

Hi –

On Sun, 4 Nov 2007, Belorion wrote:

> Instead of rescuing the error (when ‘foo’ is not found), it still gets  
> thrown.

It’s because the bare “rescue” only rescues errors that are  
descendants of StandardError. Otherwise you have to specify the ones  
you want:

rescue LoadError

David

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 3, 2007, 8:12pm UTC](https://www.ruby-forum.com/t/dynamic-requires/119144/3 "2007-11-03T20:12:42Z")

</div>

I did not know that! (obviously).

Much appreciated.

Matt
