I'm trying to handle loading invalid YAML data in Ruby, but seem to be unable to rescue exceptions raised by psych.
This is some example code to demonstrate the issue I'm having:
require 'yaml'
begin
YAML.load('&*%^*')
rescue
puts "Rescued"
end
And the exception:
# ruby test.rb
/usr/lib64/ruby/1.9.1/psych.rb:203:in `parse': (<unknown>): did not find expected alphabetic or numeric character while scanning an anchor at line 1 column 1 (Psych::SyntaxError)
from /usr/lib64/ruby/1.9.1/psych.rb:203:in `parse_stream'
from /usr/lib64/ruby/1.9.1/psych.rb:151:in `parse'
from /usr/lib64/ruby/1.9.1/psych.rb:127:in `load'
from test.rb:3:in `<main>'