【发布时间】:2012-04-20 12:05:54
【问题描述】:
begin
. . .
# error occurs here
. . .
rescue => error
puts "Error: " + error.message
end
有没有办法获取发生错误的语句的行号?
【问题讨论】:
标签: ruby exception exception-handling
begin
. . .
# error occurs here
. . .
rescue => error
puts "Error: " + error.message
end
有没有办法获取发生错误的语句的行号?
【问题讨论】:
标签: ruby exception exception-handling
只需回溯:
begin
. . .
# error occurs here
. . .
rescue => error
puts "Error: " + error.message
puts error.backtrace
end
仅获取行号 - 只需通过正则表达式将其从回溯中解析出来。
更多信息可以在这里找到:Catching line numbers in ruby exceptions
【讨论】: