From: tagomoris@... Date: 2018-06-08T08:58:28+00:00 Subject: [ruby-core:87454] [Ruby trunk Bug#14835] Impossible to know whether an exception was rescued or not using TracePoint Issue #14835 has been reported by tagomoris (Satoshi TAGOMORI). ---------------------------------------- Bug #14835: Impossible to know whether an exception was rescued or not using TracePoint https://bugs.ruby-lang.org/issues/14835 * Author: tagomoris (Satoshi TAGOMORI) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.0preview2 (2018-05-31 trunk 63539) [x86_64-darwin17] * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- TracePoint supports :raise and :return events, and :return event will be invoked when an exception occurs in a method. But its TracePoint block parameter instance doesn't have any information about raised exceptions. That means, we can know an exception was raised in a method, but we cannot know an exception was rescued or not there. ```ruby def thrower raise "exception" end def caller_without_rescue thrower end tp = TracePoint.trace(:raise, :return) do |tp| case tp.event when :raise p(here: "trace", event: :raise, klass: tp.defined_class, method: tp.method_id, exception: tp.raised_exception) else p(here: "trace", event: tp.event, klass: tp.defined_class, method: tp.method_id, value: tp.return_value) end end caller_with_rescue puts "\n----------------------\n" begin caller_without_rescue rescue => e2 puts "outer rescue: #{e2}" end ``` The script above shows these events, but TracePoint events are completely same in these two examples. ``` # caller_with_rescue {:here=>"trace", :event=>:raise, :klass=>Object, :method=>:thrower, :exception=>#} {:here=>"trace", :event=>:return, :klass=>Object, :method=>:thrower, :value=>nil} rescue: exception {:here=>"trace", :event=>:return, :klass=>Object, :method=>:caller_with_rescue, :value=>nil} ---------------------- # caller_without_rescue {:here=>"trace", :event=>:raise, :klass=>Object, :method=>:thrower, :exception=>#} {:here=>"trace", :event=>:return, :klass=>Object, :method=>:thrower, :value=>nil} {:here=>"trace", :event=>:return, :klass=>Object, :method=>:caller_without_rescue, :value=>nil} outer rescue: exception ``` My expectation is that TracePoint instance should contain exception instance in `raised_exception` at the time when it's not rescued. -- https://bugs.ruby-lang.org/ Unsubscribe: