[Ruby] Catching an error when using class methods

Evan Phoenix evan at fallingsnow.net
Thu Jul 19 09:47:15 PDT 2007


On Jul 19, 2007, at 9:18 AM, Ryan Davis wrote:

>
> On Jul 19, 2007, at 07:59 , Ofer Matan wrote:
>
>> I am sorry to have missed the BBQ - but I caught a summer cold/
>> cough and
>> though it would be better for all concerned if I stay home....
>>
>> To my question:
>>
>> Is there an easy way to catch exceptions for all methods in a
>> class? I am
>> wrapping another class and use its methods in many of my methods
>> and would
>> like to avoid using begin/rescue in each method.
>
> Sooo... you're just being lazy? Why?

If there is an exception being raised, you really should be handling  
it. Blindly disregarding it will give you nothing but trouble.

>
>> Are there better solutions now for this ?
>
> Get a better text editor.
>
> Clever code like you linked to is bad.
>
> One thing to point out is that you don't need the begin and extra
> level of indentation:
>
> def blah
>    # ... code
> rescue
>    # ... handler
> end
>
> but that's really just 1 line and some spaces. Functionally they're
> equivalent.
>
> _______________________________________________
> Ruby at zenspider.com - Seattle.rb non-commercial list
> http://www.zenspider.com/seattle.rb
> http://www.zenspider.com/mailman/listinfo/ruby



More information about the Ruby mailing list