Reputation: 1745
In my Rails 3 app, I am fetching path_info by:
Rails.application.routes.recognize_path(url, { :method => request.request_method }) rescue {}
If a crawler hits a URL like "http://localhost:3000/admin_", the above code raises following error:
LoadError: Expected /Users/user/myRailsApp/app/controllers/admin_controller.rb to define Admin_Controller
from /Users/user/.rvm/gems/ree-1.8.7-2012.02/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:492:in `load_missing_constant'
I have two questions:
rescue
not working? If I change it to rescue LoadError => e
, exception is handled gracefully.Upvotes: 2
Views: 569
Reputation: 176562
If you omit the exception type, by default rescue
will rescue only StandardError
exceptions and subclasses.
LoadError
doesn't inherit from StandardError
:
LoadError.ancestors
=> [LoadError, ScriptError, Exception, Object, Kernel, BasicObject]
Therefore, the one-line rescue pattern doesn't work with a LoadError
.
Upvotes: 1