当我打电话Exception#backtrace_locations
时,它通常按预期返回一个数组:
begin
raise "foo"
rescue => e
p e.backtrace_locations
end
# => ["this_file:2:in `<main>'"]
如果我提出ArgumentError
,这也是一样的手动:
begin
raise ArgumentError.new
rescue => e
p e.backtrace_locations
end
# => ["this_file:2:in `<main>'"]
但是,当我提出真实的ArgumentError
时通过调用参数数量错误的方法,backtrace_locations
是 nil
,这出乎我的意料:
def foo; end
begin
foo(:bar)
rescue => e
p e.backtrace_locations
end
# => nil
同样情况下,经典Exception#backtrace
按预期返回一个数组:
def foo; end
begin
foo(:bar)
rescue => e
p e.backtrace
end
# => ["this_file:1:in `foo'", "this_file:4:in `<main>'"]
返回值是Exception#backtrace_locations
是nil
在上面的第三种情况下是有意的吗?如果是这样,Exception#backtrace_locations
什么时候出现?成为nil
?有这方面的文档吗?或者,这是一个 Ruby 错误吗?
此时,我认为这是一个错误,并且reported it .
最佳答案
这是一个错误,维护者 ko1 只是 fixed it修订版 44411 中。希望它能纳入今天的 Ruby 2.1 版本中。
编辑结果发现它还没有修复。今天发布的 Ruby 2.1 仍然存在这个问题。
编辑 据维护者称,该修复将合并到 Ruby 2.1.1 中。
关于ruby - ArgumentError 是否缺少 backtrace_locations?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20765660/