Class: TracePoint

Object show all
Defined in:


A class that provides the functionality of Kernel#set_trace_func in a nice Object-Oriented API.


We can use TracePoint to gather information specifically for exceptions:

trace = do |tp|

p [tp.lineno, tp.event, tp.raised_exception]

#=> #<TracePoint:disabled>

#=> false

0 / 0
#=> [5, :raise, #<ZeroDivisionError: divided by 0>]


If you don't specify the type of events you want to listen for, TracePoint will include all available events.

Note do not depend on current event set, as this list is subject to change. Instead, it is recommended you specify the type of events you want to use.

To filter what is traced, you can pass any of the following as events:


execute code on a new line


start a class or module definition


finish a class or module definition


call a Ruby method


return from a Ruby method


call a C-language routine


return from a C-language routine


raise an exception


event hook at block entry


event hook at block ending


event hook at thread beginning


event hook at thread ending

Commenting is here to help enhance the documentation. For example, sample code, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

blog comments powered by Disqus