When I call Exception#backtrace_locations
, it usually returns an array, as intended:
begin
raise "foo"
rescue => e
p e.backtrace_locations
end
# => ["this_file:2:in `<main>'"]
This is the same if I raise an ArgumentError
manually:
begin
raise ArgumentError.new
rescue => e
p e.backtrace_locations
end
# => ["this_file:2:in `<main>'"]
However, when I raise a real ArgumentError
by calling a method with wrong number of arguments, the backtrace_locations
is nil
, which is unexpected to me:
def foo; end
begin
foo(:bar)
rescue => e
p e.backtrace_locations
end
# => nil
Under the same situation, the classic Exception#backtrace
returns an array, as intended:
def foo; end
begin
foo(:bar)
rescue => e
p e.backtrace
end
# => ["this_file:1:in `foo'", "this_file:4:in `<main>'"]
Is the return value of Exception#backtrace_locations
being nil
in the third case above intended? If so, when does Exception#backtrace_locations
become nil
? Is there any documentation for this? Or, is it a Ruby bug?
At this point, I think it is a bug, and reported it.