From: Paul Brannan Date: 2003-03-22T01:01:00+09:00 Subject: Re: class level Exception handling On Fri, Mar 21, 2003 at 01:08:30AM +0900, Xiangrong Fang wrote: > in the above code, I do a lot of TCP Socket related work in method1 > method2 etc. I would like to return false for all these methods if > there's any error, can I do better than use a begin/rescue/end for every > of them? I'm not convinced this is a good idea, because by eating the exceptions, a lot of good error information could be lost. With that in mind, how about: class A def handle_exceptions begin yield return true rescue return false end end def method1 handle_exceptions do puts "just testing" raise RuntimeError end end def method2 handle_exceptions do puts "no problem here" end end end method1 will return false, because in Ruby, the last value evaluated in a method gets returned. Paul