[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

No Rescue from RubyGem's require__ ?

Trans

4/20/2005 5:16:00 PM

I have the latest version of RubyGems installed and I seem to be
getting an unexpected error b/c of it:

irb(main):001:0> begin
irb(main):002:1* require 'carat/functor'
irb(main):003:1> rescue
irb(main):004:1> class Functor
irb(main):005:2> def initialize(&func) ; @func = func ; end
irb(main):006:2> def method_missing(op, *args) ; @func.call(op,
*args) ; end
irb(main):007:2> end
irb(main):008:1> end
LoadError: No such file to load -- carat/functor
from
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__'
from
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:18:in `require'
from (irb):2

Shouldn't the rescue clause be picked up?

Thanks,
T.

3 Answers

Mark Hubbart

4/20/2005 5:30:00 PM

0

On 4/20/05, Trans <transfire@gmail.com> wrote:
> I have the latest version of RubyGems installed and I seem to be
> getting an unexpected error b/c of it:
>
> irb(main):001:0> begin
> irb(main):002:1* require 'carat/functor'
> irb(main):003:1> rescue
> irb(main):004:1> class Functor
> irb(main):005:2> def initialize(&func) ; @func = func ; end
> irb(main):006:2> def method_missing(op, *args) ; @func.call(op,
> *args) ; end
> irb(main):007:2> end
> irb(main):008:1> end
> LoadError: No such file to load -- carat/functor
> from
> /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:18:in
> `require__'
> from
> /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:18:in `require'
> from (irb):2
>
> Shouldn't the rescue clause be picked up?

Without rubygems:

begin
require "nonesuch"
rescue
puts "rescued!"
end
LoadError: No such file to load -- nonesuch
from (irb):2:in `require'
from (irb):2

you need to rescue LoadError:

require 'rubygems'
==>true
begin
require "nonesuch"
rescue LoadError
puts "rescued!"
end
rescued!
==>nil

cheers,
Mark



Trans

4/20/2005 5:34:00 PM

0

Oh! I thought rescue without a specified error would catch all errors.
It must all StandardErrors then? Even so, catching the specific
LoadError is much better.
Thanks!

T.

Eric Hodel

4/20/2005 6:32:00 PM

0

On 20 Apr 2005, at 10:39, Trans wrote:

> Oh! I thought rescue without a specified error would catch all errors.
> It must all StandardErrors then?

Correct.

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04