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

前端 未结 2 1384
孤街浪徒
孤街浪徒 2021-01-07 16:05

I am trying to rescue from a ``require\': no such file to load in ruby` in order to hint the user at specifying the -I flag in case he has forgotten to do so. Basically the

2条回答
  •  情歌与酒
    2021-01-07 16:51

    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.

提交回复
热议问题