eval.c: refactor exception cause

* eval.c (setup_exception): set up cause after exception to be raised
  is fixed.  [Feature #8257]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43684 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-11-15 14:08:49 +00:00
parent e7d29c6cda
commit 549b35c1dc
2 changed files with 45 additions and 7 deletions

View file

@ -479,16 +479,31 @@ end.join
def test_cause
msg = "[Feature #8257]"
cause = nil
e = assert_raise(StandardError) {
begin
raise msg
rescue => e
assert_nil(e.cause, msg)
cause = e.cause
raise StandardError
end
}
assert_nil(cause, msg)
cause = e.cause
assert_instance_of(RuntimeError, cause, msg)
assert_equal(msg, cause.message, msg)
end
def test_cause_reraised
msg = "[Feature #8257]"
cause = nil
e = assert_raise(RuntimeError) {
begin
raise msg
rescue => e
raise e
end
}
assert_not_same(e, e.cause, "#{msg}: should not be recursive")
end
end