aboutsummaryrefslogtreecommitdiffstats
path: root/eval_error.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-27 21:45:30 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-27 21:45:30 +0000
commit48af6fd544e0b3cec83af9a629059ff8d304720c (patch)
tree4a1fdbb1658f6df1921b14091d65e4d12f48cc92 /eval_error.c
parent1346e39ce6e3cef0f120efde4ebf13ae045ecc02 (diff)
downloadruby-48af6fd544e0b3cec83af9a629059ff8d304720c.tar.gz
Print exception's cause like Java
Print `cause` of the exception if the exception is not caught and printed its backtraces and error message [Feature #8257] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval_error.c')
-rw-r--r--eval_error.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/eval_error.c b/eval_error.c
index 8f98fcc319..6ce2a8f9a2 100644
--- a/eval_error.c
+++ b/eval_error.c
@@ -220,6 +220,29 @@ print_backtrace(const VALUE eclass, const VALUE errat, const VALUE str, int reve
}
}
+VALUE rb_get_message(VALUE exc);
+
+static void
+show_cause(VALUE errinfo, VALUE str, VALUE highlight, VALUE reverse)
+{
+ VALUE cause = rb_attr_get(errinfo, id_cause);
+ if (!NIL_P(cause)) {
+ volatile VALUE eclass = CLASS_OF(cause);
+ VALUE errat = rb_get_backtrace(cause);
+ VALUE emesg = rb_get_message(cause);
+ if (reverse) {
+ show_cause(cause, str, highlight, reverse);
+ print_errinfo(eclass, errat, emesg, str, highlight!=0);
+ print_backtrace(eclass, errat, str, FALSE);
+ }
+ else {
+ print_backtrace(eclass, errat, str, TRUE);
+ print_errinfo(eclass, errat, emesg, str, highlight!=0);
+ show_cause(cause, str, highlight, reverse);
+ }
+ }
+}
+
void
rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlight, VALUE reverse)
{
@@ -254,17 +277,17 @@ rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlig
len = p - (msg = buff);
}
write_warn2(str, msg, len);
+ show_cause(errinfo, str, highlight, reverse);
print_backtrace(eclass, errat, str, TRUE);
print_errinfo(eclass, errat, emesg, str, highlight!=0);
}
else {
print_errinfo(eclass, errat, emesg, str, highlight!=0);
print_backtrace(eclass, errat, str, FALSE);
+ show_cause(errinfo, str, highlight, reverse);
}
}
-VALUE rb_get_message(VALUE exc);
-
void
rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo)
{