8
begin
. . .
# error occurs here
. . .
rescue => error
puts "Error: " + error.message
end
有没有办法让行号为的错误发生的地方?是否有可能得到导致错误的行号?
begin
. . .
# error occurs here
. . .
rescue => error
puts "Error: " + error.message
end
有没有办法让行号为的错误发生的地方?是否有可能得到导致错误的行号?
就拿回溯:
begin
. . .
# error occurs here
. . .
rescue => error
puts "Error: " + error.message
puts error.backtrace
end
要获得唯一的行号 - 只需通过一个正则表达式解析出来回溯的。
更多信息可以在这里找到:Catching line numbers in ruby exceptions