[LRUG] Exceptions as a flow control mechanism

James Adam james.adam at gmail.com
Wed Dec 19 02:50:10 PST 2007


I think we've talked about this before, but Rails 2.0 has taken a
stance so I thought it might be interesting to pick the "Best Minds In
London" (i.e. you filthy lot) about the use of exception handling as a
form of flow control.

I'm talking about this:
http://almosteffortless.com/2007/10/08/graceful-404s-in-rails-20/

Which is, to summarise, advocating throwing an exception when, say,
you can't find a particular record with that ID, and then letting some
Rails magic pick up the pieces and run a method accordingly.

I'd always thought that exceptions shouldn't really be used for this,
although I don't have a particularly solid justification for this
belief. Am I wrong? What do you think?

Actually, here's the quote, and I take issue with a different aspect
of it here too:

 "Lots of common exceptions would do better to be rescued at a shared
level rather than per action. This has always been possible by
overwriting rescue_action_in_public, but then you had to roll out your
own case statement and call super. Bah. So now we have a class level
macro called rescue_from, which you can use to declaratively point
certain exceptions to a given action."

Surely "rescue_action_in_public" was only there to handle unforseen
catastrophic errors? It seems like massive overkill/folly for anyone
to try and use this to handle ActiveRecord::RecordNotFound, right?

-- 
* J *
  ~



More information about the Chat mailing list