# IRB.load\_modules Bug?

**URL:** <https://rubytalk.org/t/irb-load-modules-bug/42721>\
**Category:** ruby-talk\
**Created:** [4 December 2007 05:41 UTC](https://rubytalk.org/t/irb-load-modules-bug/42721 "2007-12-04T05:41:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Curt\_Sampson](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@Curt\_Sampson](https://rubytalk.org/u/Curt_Sampson)\
**Post date:** [4 December 2007 05:41 UTC](https://rubytalk.org/t/irb-load-modules-bug/42721/1 "2007-12-04T05:41:05Z")

</div>

irb/init.rb contains the following code:

&nbsp;&nbsp;def IRB.load\_modules  
&nbsp;&nbsp;&nbsp;&nbsp;for m in @CONF[:LOAD\_MODULES]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require m  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rescue  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print $@[0], ":", $!.class, ": ", $!, "\n"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end

Unfortunately, that rescue does not appear to catch LoadError, at least  
on my system (ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-netbsdelf]).  
Is it supposed to?

cjs

> **···**
>
> --  
> Curt Sampson \<[cjs@starling-software.com](mailto:cjs@starling-software.com)\> +81 90 7737 2974  
> Starling Software \<[office-admin@starling-software.com](mailto:office-admin@starling-software.com)\>  
> Mobile sites and software consulting: [http://www.starling-software.com](http://www.starling-software.com)

---

<div class="post-metadata">

**Author:** ![Jordan\_Callicoat](https://avatars.discourse-cdn.com/v4/letter/j/9de053/32.png) [@Jordan\_Callicoat](https://rubytalk.org/u/Jordan_Callicoat)\
**Post date:** [4 December 2007 06:45 UTC](https://rubytalk.org/t/irb-load-modules-bug/42721/2 "2007-12-04T06:45:02Z")

</div>

I'm not sure of the intended behavior, but in 1.9 it has...

rescue # StandardError, ScriptError

...which makes me think that LoadError is intentionally not rescued.

I've put the following in my .ircrb...

def IRB.load\_modules  
&nbsp;&nbsp;errors =   
&nbsp;&nbsp;for m in @CONF[:LOAD\_MODULES]  
&nbsp;&nbsp;&nbsp;&nbsp;begin  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require m  
&nbsp;&nbsp;&nbsp;&nbsp;rescue # StandardError, ScriptError  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print $@[0], ":", $!.class, ": ", $!, "\n"  
&nbsp;&nbsp;&nbsp;&nbsp;rescue LoadError =\> e  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;errors \<\< "\n\*\*\* #{e.message}"  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
&nbsp;&nbsp;puts "#{errors.join('')}\n\n" unless errors.empty?  
end

Regards,  
Jordan

> **···**
>
> On Dec 3, 11:41 pm, Curt Sampson \<c...@cynic.net\> wrote:
> 
> > irb/init.rb contains the following code:
> > 
> > &nbsp;&nbsp;def IRB.load\_modules  
> > &nbsp;&nbsp;&nbsp;&nbsp;for m in @CONF[:LOAD\_MODULES]  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require m  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rescue  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print $@[0], ":", $!.class, ": ", $!, "\n"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;end
> > 
> > Unfortunately, that rescue does not appear to catch LoadError, at least  
> > on my system (ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-netbsdelf]).  
> > Is it supposed to?
> > 
> > cjs  
> > --  
> > Curt Sampson \<c...@starling-software.com\> +81 90 7737 2974  
> > Starling Software \<office-ad...@starling-software.com\>  
> > Mobile sites and software consulting:[http://www.starling-software.com](http://www.starling-software.com)
