I see a very interesting and catastrophic behavior with ruby, see code below
class ExceptionTest def test @result = [0]*500000 begin no_such_method rescue Exception => ex puts "before #{ex.class}" st = Time.now ex.message puts "after #{Time.now-st} #{ex.message}" end end end ExceptionTest.new.test
Ideally, ex.message should not take any time, and therefore the time should be in ms, but here is the output
before NameError after 0.462443 undefined local variable or method `no_such_method' for #<ExceptionTest:0x007fc74a84e4f0>
If I assign [0]*500000 local variable instead of an instance variable, for example. result = [0]*500000 runs as expected
before NameError after 2.8e-05 undefined local variable or method `no_such_method' for #<ExceptionTest:0x007ff59204e518>
It seems that somehow ex.message looping on instance variables, why do this, please enlighten me!
I tried it on ruby ruby-1.9.2-p290, ruby-1.9.1-p376, ruby 2.0.0 and any version of Ruby on codepad.org.
Edit: file contains error http://bugs.ruby-lang.org/issues/8366
source share