diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-10 13:16:33 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-10 13:16:33 +0000 |
commit | b050cc5ab9b0774bbd16f49f4787f50b07c566fe (patch) | |
tree | 959cb4adedf0859ee1979938bb95e27c81a80bba /error.c | |
parent | 2fff948394f1baab5bc97aca5ceab81b087c4bc4 (diff) |
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
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -780,6 +780,14 @@ rb_exc_set_backtrace(VALUE exc, VALUE bt) return exc_set_backtrace(exc, bt); } +VALUE +exc_cause(VALUE exc) +{ + ID id_cause; + CONST_ID(id_cause, "cause"); + return rb_attr_get(exc, id_cause); +} + static VALUE try_convert_to_exception(VALUE obj) { @@ -1742,6 +1750,7 @@ Init_Exception(void) rb_define_method(rb_eException, "inspect", exc_inspect, 0); rb_define_method(rb_eException, "backtrace", exc_backtrace, 0); rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1); + rb_define_method(rb_eException, "cause", exc_cause, 0); rb_eSystemExit = rb_define_class("SystemExit", rb_eException); rb_define_method(rb_eSystemExit, "initialize", exit_initialize, -1); |