summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--error.c12
-rw-r--r--test/ruby/test_exception.rb10
2 files changed, 17 insertions, 5 deletions
diff --git a/error.c b/error.c
index 92c35d5d67..85d9581689 100644
--- a/error.c
+++ b/error.c
@@ -1162,19 +1162,21 @@ VALUE
rb_get_backtrace(VALUE exc)
{
ID mid = id_backtrace;
+ VALUE info;
if (rb_method_basic_definition_p(CLASS_OF(exc), id_backtrace)) {
- VALUE info, klass = rb_eException;
+ VALUE klass = rb_eException;
rb_execution_context_t *ec = GET_EC();
if (NIL_P(exc))
return Qnil;
EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, exc, mid, mid, klass, Qundef);
info = exc_backtrace(exc);
EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, exc, mid, mid, klass, info);
- if (NIL_P(info))
- return Qnil;
- return rb_check_backtrace(info);
}
- return rb_funcallv(exc, mid, 0, 0);
+ else {
+ info = rb_funcallv(exc, mid, 0, 0);
+ }
+ if (NIL_P(info)) return Qnil;
+ return rb_check_backtrace(info);
}
/*
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 8dafa45120..fddb0f3a0f 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -1236,6 +1236,16 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
raise RuntimeError, "hello"
}
end;
+
+ error_class = Class.new(StandardError) do
+ def backtrace; :backtrace; end
+ end
+ begin
+ raise error_class
+ rescue error_class => e
+ assert_raise(TypeError) {$@}
+ assert_raise(TypeError) {e.full_message}
+ end
end
def test_backtrace_in_eval