This is actually 3 part question:
- What are all the exceptions Psych throws?
- How do you know which ones they are when documentation doesn't bother to list them?
- Sample code to catch all possible YAML.load_file exceptions?
I wouldn't ask for no 3 but this question suggests I will encounter wierd issues: Can't rescue YAML.load exception
Based on this question How to know what exceptions to rescue
I got:
Psych::Exception
Psych::BadAlias
Psych::DisallowedClass
Psych::SyntaxError
But when I try to catch that code still fails
irb(main):002:0> begin
irb(main):003:1* YAML.load_file('test_file_does_not_exist')
irb(main):004:1> rescue Psych::Exception
irb(main):005:1> puts $!.message
irb(main):006:1> end
Errno::ENOENT: No such file or directory @ rb_sysopen - test
from /home/marko/.gem/ruby/2.3.1/gems/psych-2.1.0/lib/psych.rb:474:in `initialize'
from /home/marko/.gem/ruby/2.3.1/gems/psych-2.1.0/lib/psych.rb:474:in `open'
from /home/marko/.gem/ruby/2.3.1/gems/psych-2.1.0/lib/psych.rb:474:in `load_file'
from (irb):3
from /home/marko/.rubies/ruby-2.3.1/bin/irb:11:in `<main>'
I am looking for ways to catch all of that nonsense. Regardless for the reason of failure, I want to catch it and display a message before it falls back to main exception handling code.
Microsoft, which I don't particularly like, shows all exceptions for every class they ever wrote. Example: https://msdn.microsoft.com/en-us/library/b9skfh7s(v=vs.110).aspx