Does Ruby Rescue Instructions Follow?

Does Ruby rescue statement modifier work with require ?

 irb(main):001:0> require 'a' rescue nil LoadError: no such file to load -- a from (irb):1:in `require' from (irb):1 from :0 
+4
source share
1 answer

You can save from LoadError you just need to use the begin/end style, and not use the built-in rescue :

This works the way you expect:

 begin require 'a' rescue LoadError => ex puts "Load error: #{ex.message}" end 
+4
source

Source: https://habr.com/ru/post/1438048/


All Articles