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:0x007f786a452448>

#=> #<TracePoint:0x007f786a452448>

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