How do I determine which exception handler rescue_from will choose in Rails? How do I determine which exception handler rescue_from will choose in Rails? ruby-on-rails ruby-on-rails

How do I determine which exception handler rescue_from will choose in Rails?


The 404 handler never gets called because the catch all always gets called first in your example. The problem is in the ordering of the handler definitions. They are evaluated from bottom to top meaning that your last defined handler will have the highest priority and your first defined handler will have the lowest priority. If you switch the order then you will get the behavior you want.

# Catch all unhandled exceptionsrescue_from StandardError do |e|  ...end# ActiveRecord 404rescue_from ActiveRecord::RecordNotFound do |e|  ...end