我试图从一个"require"中解救出来:没有这样的文件可以按顺序加载到ruby中
begin
require 'someFile.rb'
rescue
puts "someFile.rb was not found, have you"
puts "forgotten to specify the -I flag?"
exit
end
我原以为在someFile.rb
号案件没有找到的情况下,rescue
号零件将接管执行,但我的假设是错误的.
我试图从一个"require"中解救出来:没有这样的文件可以按顺序加载到ruby中
begin
require 'someFile.rb'
rescue
puts "someFile.rb was not found, have you"
puts "forgotten to specify the -I flag?"
exit
end
我原以为在someFile.rb
号案件没有找到的情况下,rescue
号零件将接管执行,但我的假设是错误的.
rescue没有争论只能挽救StandardError秒.LoadError(由未找到的文件引发)不是StandardError而是ScriptError(参见http://blog.nicksieger.com/articles/2006/09/06/rubys-exception-hierarchy).因此,正如MBO所指出的,你必须明确地拯救LoadError.