summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-15 14:08:49 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-15 14:08:49 +0000
commit549b35c1dc771d233a72466a6cae8363908f3350 (patch)
tree78e6b127454a068f74f62bd6b5b631216d0be578 /eval.c
parente7d29c6cdadbb08d39219a05d795fe6c38414e19 (diff)
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
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/eval.c b/eval.c
index a398479fb2..5b67e1a003 100644
--- a/eval.c
+++ b/eval.c
@@ -431,6 +431,34 @@ rb_frozen_class_p(VALUE klass)
}
NORETURN(static void rb_longjmp(int, volatile VALUE));
+static VALUE get_errinfo(void);
+static VALUE get_thread_errinfo(rb_thread_t *th);
+
+static VALUE
+exc_setup_cause(VALUE exc, VALUE cause)
+{
+ ID id_cause;
+ CONST_ID(id_cause, "cause");
+
+#if SUPPORT_JOKE
+ if (NIL_P(cause)) {
+ ID id_true_cause;
+ CONST_ID(id_true_cause, "true_cause");
+
+ cause = rb_attr_get(rb_eFatal, id_true_cause);
+ if (NIL_P(cause)) {
+ cause = rb_exc_new_cstr(rb_eFatal, "because using such Ruby");
+ rb_ivar_set(cause, id_cause, INT2FIX(42)); /* the answer */
+ OBJ_FREEZE(cause);
+ rb_ivar_set(rb_eFatal, id_true_cause, cause);
+ }
+ }
+#endif
+ if (!NIL_P(cause) && cause != exc) {
+ rb_ivar_set(exc, id_cause, cause);
+ }
+ return exc;
+}
static void
setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg)
@@ -447,6 +475,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg)
if (NIL_P(mesg)) {
mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
}
+ exc_setup_cause(mesg, get_thread_errinfo(th));
file = rb_sourcefile();
if (file) line = rb_sourceline();
@@ -552,8 +581,6 @@ rb_interrupt(void)
rb_raise(rb_eInterrupt, "%s", "");
}
-static VALUE get_errinfo(void);
-
/*
* call-seq:
* raise
@@ -641,10 +668,6 @@ make_exception(int argc, VALUE *argv, int isstr)
if (argc > 2)
set_backtrace(mesg, argv[2]);
}
- {
- VALUE cause = get_errinfo();
- if (!NIL_P(cause)) rb_iv_set(mesg, "cause", cause);
- }
return mesg;
}