From: "Jan E." Date: 2012-04-13T19:13:17+09:00 Subject: Re: How to make the "rescue" expression in a method Hi, You can define the method to accept a block and rescue exceptions coming from the block: def execute_and_rescue begin yield # execute the block rescue StandardError => error puts error.message end end execute_and_rescue do 1/0 end Some things to note: - You current method definition doesn't really make sense, because you neither do actual error handling nor do you suppress the error. What's the purpose of the method? If you only want to change how error messages are displayed, you should wrap the whole script in a begin-end block. - It doesn't make sense to define the method as a singleton method of class. If you want to use it everywhere, define it in the Kernel module. Otherwise, define it in the specific class. - Don't rescue instances of Exception, because this class also includes system errors that you shouldn't touch. Rescue StandardError instead (or even better: specific error classes). - You can save the exact error object in the rescue block (see above). Then you don't have to rely on the $! global variable. -- Posted via http://www.ruby-forum.com/.