errors/backtrace/names_as_given.rb
tests/_examples/errors/backtrace/names_as_given.rb in the metorex repository.
# A backtrace names the program file the way the command line gave it, and
# a NameError names the line of the bare name it could not find.
begin
nope
rescue NameError => error
p(error.backtrace)
end
def go
missing
end
begin
go
rescue NameError => error
p(error.backtrace)
end
Output:
["tests/_examples/errors/backtrace/names_as_given.rb:4:in '<main>'"]
["tests/_examples/errors/backtrace/names_as_given.rb:10:in 'Object#go'", "tests/_examples/errors/backtrace/names_as_given.rb:14:in '<main>'"]