From: headius@... Date: 2016-02-14T10:30:57+00:00 Subject: [ruby-core:73802] [Ruby trunk Bug#12068] raise overwrites exception cause even if exception is not new Issue #12068 has been updated by Charles Nutter. May I backport this change to 2.3? Matz? I believe the original behavior was unintentional and should be fixed. ---------------------------------------- Bug #12068: raise overwrites exception cause even if exception is not new https://bugs.ruby-lang.org/issues/12068#change-56984 * Author: Charles Nutter * Status: Closed * Priority: Normal * Assignee: * ruby -v: 2.3.0 * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- 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: ```ruby 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 [#, #] [#, #] ``` 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 [#, #] [#, #] ``` -- https://bugs.ruby-lang.org/ Unsubscribe: