Is it possible to get the line number that threw an error?
exception, ruby
Solution
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
Problem
``` 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?