How to Rescue from a 'Require': No Such File to Load in Ruby

How do I rescue from a `require': no such file to load in ruby?

rescue without arguments rescues only StandardError s. The LoadError (that is raised by a file not found) is not a StandardError but a ScriptError (see http://blog.nicksieger.com/articles/2006/09/06/rubys-exception-hierarchy). Therefore you have to rescue the LoadError explicitly, as MBO indicated.

Ruby 'require' error: cannot load such file

I just tried and it works with require "./tokenizer". Hope this helps.

ruby gem require_relative cannot load such file

I got this working by copying everything out of interface.rb deleting the file and recreating it. Strange why that happened.



Related Topics



Leave a reply



Submit