error.c: Exception#cause

* error.c (exc_cause): captured previous exception.
* eval.c (make_exception): capture previous exception automagically.
  [Feature #8257]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-11-10 13:16:33 +00:00
parent 2fff948394
commit b050cc5ab9
4 changed files with 35 additions and 0 deletions

View file

@ -476,4 +476,19 @@ end.join
def test_stackoverflow
assert_raise(SystemStackError){m}
end
def test_cause
msg = "[Feature #8257]"
e = assert_raise(StandardError) {
begin
raise msg
rescue => e
assert_nil(e.cause, msg)
raise StandardError
end
}
cause = e.cause
assert_instance_of(RuntimeError, cause, msg)
assert_equal(msg, cause.message, msg)
end
end