tag:blogger.com,1999:blog-12467669.post2485549654631186634..comments2023-04-29T07:23:25.825-04:00Comments on Jay Fields' Thoughts: Ruby: Inline RescueJayhttp://www.blogger.com/profile/14491442812573747680noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-12467669.post-12605576015559157382008-08-12T01:10:00.000-04:002008-08-12T01:10:00.000-04:00Wow I like the parentheses mentioned in the commen...Wow I like the parentheses mentioned in the comments. Suppose I should use more of those.<BR/>I'm a fan of inline rescue, too, though...they're a little scary. andand might help out in the case of it returning nil.<BR/>Take care.<BR/>-RAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-55905648047702018162008-04-24T17:31:00.000-04:002008-04-24T17:31:00.000-04:00you wanted to express it as a single line - Easy a...you wanted to express it as a single line - Easy and great. Anyway, I always have a twitch on my left eye when I see this "klass" idiom. Here:<BR/><BR/>@presenter = ("#{action}_presenter".camelize.constantize rescue Presenter).new<BR/><BR/>Parenthesis are a great tool, and often underused in Ruby :)Gunnar Wolfhttps://www.blogger.com/profile/01596337686809335591noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-7653908958577859212008-02-24T23:35:00.000-05:002008-02-24T23:35:00.000-05:00Hey Toby,Yeah, that's probably a better solution. ...Hey Toby,<BR/>Yeah, that's probably a better solution. Rescuing was the first thing that came to mind and it just worked so I never gave it another thought.<BR/><BR/>Cheers, JayAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-58455514742164835672008-02-24T18:28:00.000-05:002008-02-24T18:28:00.000-05:00his reminds me of on error resume next in vb :Dhis reminds me of on error resume next in vb :DAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-26915791289009612562008-02-24T16:38:00.000-05:002008-02-24T16:38:00.000-05:00Hi Jay,Did you consider using const_defined? inste...Hi Jay,<BR/><BR/>Did you consider using const_defined? instead of rescue? "Exceptions are for Exceptional circumstances" and all that.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-25435546998736279102008-02-24T16:20:00.000-05:002008-02-24T16:20:00.000-05:00Here's a line that I include in every project..xml...Here's a line that I include in every project..<BR/><BR/>xml.append! begin render( :partial => "layouts/#{controller.controller_name}" ) rescue yield end<BR/><BR/>I use builder for templates and append! is a method I added that works just like << except adds indentation. So render the controller template, or just show the action if there isn't one.<BR/><BR/>I don't use inline rescue much, but it's nice to have sometimes. :)Brennan Falknerhttps://www.blogger.com/profile/11501453237566361813noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-7580602266514767142008-02-24T13:51:00.000-05:002008-02-24T13:51:00.000-05:00I'm a fan of inline rescue's as well, but I think ...I'm a fan of inline rescue's as well, but I think its important to use them judiciously. In your example you're executing a very specific set of methods and there's not many types of errors that could be thrown...which creates a great place to use an inline rescue. The flip side that I've seen is that people will do things like:<BR/><BR/>obj = some.complex.calls.and.logic rescue nil<BR/><BR/>where the chain of events could do anything from throw an ActiveRecord error to a LoadError, or more. The more responsible thing IMHO in places like that is to be specific about what error you're catching, which will force you to split things out over multiple lines in a block format.Jack Dempseyhttps://www.blogger.com/profile/17940809933407388413noreply@blogger.com