From: Gary Wright Date: 2011-10-20T08:41:24+09:00 Subject: Re: efficient way to catch & continue on exception On Oct 19, 2011, at 2:49 PM, Kassym Dorsel wrote: > > I have the following : > > hs = {} > hs.default = nil > hs['name3'] = command3 > hs['name2'] = command2 > hs['name1'] = command1 > > Where command* are methods that can fail and raise an exception. The > only way I know to deal with this is : A couple options: hs = {} hs['name3'] = (command3 rescue nil) hs['name2'] = (command2 rescue nil) hs['name1'] = (command1 rescue nil) Or how about: module Capture def capture(key) self[key] = yield rescue self[key] = nil end end hs = {}.extend Capture hs.capture('name3') { command3 } hs.capture('name2') { command2 } hs.capture('name1') { command1 }