Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
`Exception#cause` is difference behavior with CRuby 2.3.0 #3654
I found difference behavior of
begin raise 'cause a' rescue begin raise 'cause b' rescue => ex p [ex, ex.cause] end end begin begin raise 'cause a' rescue => a begin raise 'cause b' rescue raise a end end rescue => ex p [ex, ex.cause] end
I got following results.
% ruby -v cause.rb jruby 184.108.40.206 (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64-Bit Server VM 25.72-b15 on 1.8.0_72-b15 +jit [darwin-x86_64] [#<RuntimeError: cause b>, #<RuntimeError: cause a>] [#<RuntimeError: cause a>, nil] % ruby -v cause.rb ruby 2.3.0p5 (2016-01-15 revision 53536) [x86_64-darwin15] [#<RuntimeError: cause b>, #<RuntimeError: cause a>] [#<RuntimeError: cause a>, #<RuntimeError: cause b>]
Is JRuby results intentional behavior? If it's yes, I will fix rake tests.
I'm not sure this is correct behavior in MRI, and I'll explain why.
In the differing case,
begin begin raise 'a' rescue => a begin raise 'b' rescue => b p [b, b.cause] begin raise 'c' rescue raise b end end end rescue p [$!, $!.cause] end
And the output in JRuby 220.127.116.11 and MRI 2.3.0:
MRI is losing the original cause of the exception, without it being physically replaced.
I'm going to report this as a bug.
Interestingly, JRuby 9.1 (ruby-2.3 branch) appears to work like Ruby 2.3, so somewhere along the way we "fixed" this: