[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Dynamic requires

Belorion

11/3/2007 6:36:00 PM

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

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

2 Answers

David A. Black

11/3/2007 6:49:00 PM

0

Hi --

On Sun, 4 Nov 2007, Belorion wrote:

> 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.

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

--
Upcoming training by David A. Black/Ruby Power and Light, LLC:
* Advancing With Rails, Edison, NJ, November 6-9
* Advancing With Rails, Berlin, Germany, November 19-22
* Intro to Rails, London, UK, December 3-6 (by Skills Matter)
See http://www.r... for details!

Belorion

11/3/2007 7:11:00 PM

0

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

I did not know that! (obviously).

Much appreciated.

Matt

On 11/3/07, David A. Black <dblack@rubypal.com> wrote:
>
> Hi --
>
> On Sun, 4 Nov 2007, Belorion wrote:
>
> > 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.
>
> 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
>
> --
> Upcoming training by David A. Black/Ruby Power and Light, LLC:
> * Advancing With Rails, Edison, NJ, November 6-9
> * Advancing With Rails, Berlin, Germany, November 19-22
> * Intro to Rails, London, UK, December 3-6 (by Skills Matter)
> See http://www.r... for details!
>
>