A stack trace records the active method-call sequence at a point during Ruby execution. It identifies the files, line numbers, and methods that led to an error or to the current location, making it useful for debugging. section 1.3.3 section 15.4.1
Reading an exception backtrace
An exception object exposes its call history through backtrace. For a rescued ArgumentError, entries such as fussy.rb:2:in 'fussy_method' and fussy.rb:6:in '<main>' show where the exception arose and how execution reached it. The same exception object also provides its message. section 6.4.6
Ruby exposes stack information both automatically in error output and explicitly through caller. caller returns strings ordered from the most recent call backward; caller_locations provides a parsed interface for examining stack frames. section 15.4.1 section 15.6
Tracing nested calls
If x calls y and y calls z, calling caller inside z reports y first, then x, then <main>. Replacing caller with raise produces the familiar fatal-error format, including the current frame and the calls that led there.
def x
y
end
def y
z
end
def z
puts "Stacktrace: "
p caller
end
x
Browse the minimal x-to-y-to-z program used to generate a stack trace with caller. section 15.4.1






