Raising Exceptions within Your Rails Application
Clemens Kofler has a great post about when to raise exceptions within your Rails application:
Over the years I’ve come up with a little rule of thumb for exceptions:
Libraries Should Raise, Applications Should Not Raise.
Yes, it’s as simple as that. To understand the reasons for my rule of thumb, we have to switch to the world of compiled programming languages for a second.
I couldn’t agree more!
So, now I want to pose a question back: Should controllers catch exceptions, such as those raised by find(id) within ActiveRecord, or should they fall through the generic exception handling support built into Rails?
Bonus question: Does your answer change if the caller is using XHR rather than a standard page request?