Skip to content

Commit 8ffae32

Browse files
committed
[GR-15781] Re-raising an exception no longer sets the cause.
PullRequest: truffleruby/837
2 parents 81f5b5f + 6e13509 commit 8ffae32

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Bug fixes:
88
* Added missing `BigDecimal` constant definitions (#1684).
99
* Implemented `rb_eval_string_protect`.
1010
* Fixed `rb_get_kwargs` to correctly handle optional and rest arguments.
11+
* Calling `Kernel#raise` with a raised exception will no longer set the cause of the exception to itself (#1682).
1112

1213
# 1.0 RC 17
1314

spec/ruby/core/exception/cause_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,16 @@
4141
e.cause.should equal(cause)
4242
}
4343
end
44+
45+
it "is not set to the exception itself when it is re-raised" do
46+
-> {
47+
begin
48+
raise RuntimeError
49+
rescue RuntimeError => e
50+
raise e
51+
end
52+
}.should raise_error(RuntimeError) { |e|
53+
e.cause.should == nil
54+
}
55+
end
4456
end

src/main/ruby/core/truffle/kernel_operations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def self.internal_raise(exc, msg, ctx, internal)
141141
unless skip
142142
exc.set_context ctx if ctx
143143
exc.capture_backtrace!(2) unless exc.backtrace?
144-
Truffle.invoke_primitive :exception_set_cause, exc, $!
144+
Truffle.invoke_primitive :exception_set_cause, exc, $! unless exc.equal?($!)
145145
end
146146

147147
if $DEBUG

0 commit comments

Comments
 (0)