No Rescue from RubyGem's require__ ?

T

Trans

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

Mark Hubbart

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
 
T

Trans

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

Eric Hodel

--Apple-Mail-14-423219167
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed

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

Correct.

--
Eric Hodel - (e-mail address removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

--Apple-Mail-14-423219167
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iEYEARECAAYFAkJmoAEACgkQMypVHHlsnwS42ACdFN+KENQzSSOoeCeCUUBJwHaX
Gq0AoO8QCO0g0qHuZw8dKJbEcSMJM/vr
=SuOg
-----END PGP SIGNATURE-----

--Apple-Mail-14-423219167--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top