exceptions while in views

The way my controllers work is they set up as little as possible and then call the view. It is up to the view to query the database, etc. In my particular application, there are remote queries that can fail which produces an exception which I have put a rescue_from handler for. But since the exception happens in a view, it is wrapped by an ActionView::TemplateError so the rescue_with_handler does not find my exception handler.

I just submitted a patch to a ticket I opened a month ago about this. The ticket is #2034.

I would argue that wrapping the exception in the first place is ill advised. I can understand wrapping it if it is a compile time error but not if it is an execution time error. But in any case, it seems logical that exceptions during views should be able to be handled just as exceptions during the controller processing.

Please review the changes and let me know your thoughts.

Thank you, pedz

I support this. My controllers mostly set up paginated collections that are lazy loading (i.e. they hit the database only when you try to iterate them, much like association proxies) because I use fragment caching all over the place.

All kinds of errors happen on runtime and wrapping them in a single error class does not only confuse rescue_from, but also Hoptoad and possibly other exception tracker applications that try to group similar errors together.

+1

– Yehuda