Actions
Bug #12068
closedraise overwrites exception cause even if exception is not new
Description
It appears that raise
will overwrite the original cause of an exception even when re-raising the same one. I believe this is a bug, since loses the original cause and associates the re-raised exception with a completely unrelated cause.
Example:
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
CRuby outputs:
[] ~/projects/jruby $ ruby23 cause.rb
[#<RuntimeError: b>, #<RuntimeError: a>]
[#<RuntimeError: b>, #<RuntimeError: c>]
Here, the original cause of the "b" exception (the "a" exception) is lost, replaced during the re-raise with the "c" exception.
I believe JRuby 9.0.5.0's behavior is correct here:
[] ~/projects/jruby $ rvm jruby-9.0.5.0 do ruby cause.rb
[#<RuntimeError: b>, #<RuntimeError: a>]
[#<RuntimeError: b>, #<RuntimeError: a>]
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0Like0