begin
. . .
# error occurs here
. . .
rescue => error
puts "Error: " + error.message
end
Is there a way to get the line number of the statement where the error occurred?
Just take the backtrace:
begin
. . .
# error occurs here
. . .
rescue => error
puts "Error: " + error.message
puts error.backtrace
end
To get only the line number - just parse it out of the backtrace via a regex.
More information can be found here: Catching line numbers in ruby exceptions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With