From: Logan Capaldo Date: 2005-12-18T05:18:42+09:00 Subject: Re: Rescuing SyntaxError On Dec 17, 2005, at 3:04 PM, Caleb Tennis wrote: > Is it possible to catch illegal syntax errors? > > > irb(main):001:0> 550p > SyntaxError: compile error > > ... > > # se.rb > begin > 550p > rescue SyntaxError => e > # This never seems to get run > puts "Caught a syntax error: " + e > end > > ~> ruby se.rb > blah.rb:2: syntax error > > Thanks, > Caleb > Sort of, you have to delay the compilation though: irb(main):017:0> begin irb(main):018:1* eval "550p" irb(main):019:1> rescue SyntaxError => e irb(main):020:1> puts "Caught a syntax error: " + e irb(main):021:1> end Caught a syntax error: (eval):1:in `irb_binding': compile error (eval):1: syntax error => nil