How would I retrieve the line number of the syntax error in the rescue
clause ?
Regards
Roger
Example
require “jruby-parser”
begin
root = JRubyParser.parse("begin
b = foo(1)
x = 'l
begin
x
resc
end
x = 12
end ", opts = {:version => JRubyParser::Compat::RUBY1_9, :filename
=> ‘name.rb’})
begin
root = JRubyParser.parse("begin
b = foo(1)
x = 'l
begin
x
resc
end
x = 12
end ", opts = {:version =>
JRubyParser::Compat::RUBY1_9, :filename => ‘name.rb’})
From my own experiences, I’ve found that in your rescue block, e is a
NativeException and its cause is a Ruby class which proxies for the
underlying Java org.jrubyparser.lexer.SyntaxException class. So you
need:
rescue org.jrubyparser.lexer.SyntaxException => e
puts e.cause.position.start_line, e.cause.position.file
end
Far from obvious behaviour. I had to go digging around in the JRuby
source code to figure this out.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.