Ruby救援TypeError没有捕获TypeError异常

时间:2017-04-14 14:30:46

标签: ruby typeerror rescue

我正在使用名为bindata的Gem,其中包含以下代码块:

def assign(val)
  raise ArgumentError, "can't set a nil value for #{debug_name}" if val.nil?

  unless has_parameter?(:value)
    raw_val = val.respond_to?(:snapshot) ? val.snapshot : val
    @value = begin
               raw_val.dup
             rescue TypeError
               # can't dup Fixnums
               raw_val
             end
  end
end

此代码用于复制发送到assign函数的对象,但Fixnum不能重复,因此创建者将救援块放在那里。我在Rails控制台中多次测试了这段代码,救援工作正常。但是:

I, [2017-04-08T00:03:47.165387 #27899]  INFO -- : *** below you find the most recent exception thrown, this will be likely (but not certainly) the exception that made the application exit abnormally ***
E, [2017-04-08T00:03:47.165450 #27899] ERROR -- : can't dup Fixnum (TypeError)
/home/blueserver/.rvm/gems/ruby-1.9.3-p327-turbo@symphony/gems/bindata-1.4.3/lib/bindata/base_primitive.rb:90:in `dup'
/home/blueserver/.rvm/gems/ruby-1.9.3-p327-turbo@symphony/gems/bindata-1.4.3/lib/bindata/base_primitive.rb:90:in `assign'
(eval):3:in `assign'

似乎这段代码正在捕获当时的错误%99.99,但每隔一段时间它就会崩溃。知道为什么救援会随机失败吗?我的代码充满了对Bindata宝石的调用,因此围绕每个电话进行救援将是一项繁琐的工作。

谢谢!

0 个答案:

没有答案