aboutsummaryrefslogtreecommitdiffstats
path: root/error.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-13 04:31:06 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-13 04:31:06 +0000
commit0aed7c6874ba75f1a85899d0ed0ea07b24a9f3ef (patch)
tree71350c2b48c1b2defd672ed3f672d130a7e5ebc0 /error.c
parent4547d773c2ea02864df5658a99d18718626e902d (diff)
downloadruby-0aed7c6874ba75f1a85899d0ed0ea07b24a9f3ef.tar.gz
* error.c: add Exception#backtrace_locations.
Now, there are no setter and independent from Exception#backtrace. [Feature #8960] * eval.c (setup_exception): set backtrace locations for `bt_location' special attribute. * vm_backtrace.c (rb_backtrace_to_location_ary): added. * internal.h: ditto. * test/ruby/test_backtrace.rb: add a test for Exception#backtrace_locations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/error.c b/error.c
index ac7b632751..b9d8d52809 100644
--- a/error.c
+++ b/error.c
@@ -736,6 +736,30 @@ exc_backtrace(VALUE exc)
return obj;
}
+/*
+ * call-seq:
+ * exception.backtrace_locations -> array
+ *
+ * Returns any backtrace associated with the exception. This method is
+ * similar to Exception#backtrace, but the backtrace is an array of
+ * Thread::Backtrace::Location.
+ *
+ * Now, this method is not affected by Exception#set_backtrace().
+ */
+static VALUE
+exc_backtrace_locations(VALUE exc)
+{
+ ID bt_locations;
+ VALUE obj;
+
+ CONST_ID(bt_locations, "bt_locations");
+ obj = rb_attr_get(exc, bt_locations);
+ if (!NIL_P(obj)) {
+ obj = rb_backtrace_to_location_ary(obj);
+ }
+ return obj;
+}
+
VALUE
rb_check_backtrace(VALUE bt)
{
@@ -1749,6 +1773,7 @@ Init_Exception(void)
rb_define_method(rb_eException, "message", exc_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);
rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1);
rb_define_method(rb_eException, "cause", exc_cause, 0);