summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authorsorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-12 11:47:16 +0000
committersorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-12 11:47:16 +0000
commit0d7718896cfb629ad823b9ca5004465ef2063ab8 (patch)
tree764655a01a2038af09ef45f4ae5fbeb0ff31ce42 /error.c
parent838f23ae34a634f3bbe39d27b861abc8dd853762 (diff)
error.c(exc_full_message): Exception#full_message
Add a method to retrieve a String expression of an exception, formatted in the same way that Ruby prints an uncaught exception out. [Feature #14141] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/error.c b/error.c
index d257028ad2..4b921f99ff 100644
--- a/error.c
+++ b/error.c
@@ -923,6 +923,25 @@ exc_to_s(VALUE exc)
/*
* call-seq:
+ * exception.full_message -> string
+ *
+ * Returns formatted string of <i>exception</i>.
+ * The returned string is formatted using the same format that Ruby uses
+ * when printing an uncaught exceptions to stderr. So it may differ by
+ * <code>$stderr.tty?</code> at the timing of a call.
+ */
+
+static VALUE
+exc_full_message(VALUE exc)
+{
+ VALUE str = rb_str_new2("");
+ VALUE errat = rb_get_backtrace(exc);
+ rb_ec_error_write(exc, errat, str);
+ return str;
+}
+
+/*
+ * call-seq:
* exception.message -> string
*
* Returns the result of invoking <code>exception.to_s</code>.
@@ -2189,6 +2208,7 @@ Init_Exception(void)
rb_define_method(rb_eException, "==", exc_equal, 1);
rb_define_method(rb_eException, "to_s", exc_to_s, 0);
rb_define_method(rb_eException, "message", exc_message, 0);
+ rb_define_method(rb_eException, "full_message", exc_full_message, 0);
rb_define_method(rb_eException, "inspect", exc_inspect, 0);
rb_define_method(rb_eException, "backtrace", exc_backtrace, 0);
rb_define_method(rb_eException, "backtrace_locations", exc_backtrace_locations, 0);