Justin Collins
8/16/2006 6:26:00 AM
Joe Ruby wrote:
> Justin Collins wrote:
>
>> Joe Ruby wrote:
>>
>>> Logan Capaldo wrote:
>>>
>>>
>>>> some_exception_raising_call rescue nil # This is evil
>>>>
>>>>
>>> Why is that evil?
>>>
>>> Joe
>>>
>>>
>> Because if something goes wrong in that call, you will get no
>> information about it. Won't even know it happened.
>>
>> -Justin
>>
>
> Yeah, but rescue nil is just usually to deal with null values from the
> database, for example, which isn't a big deal.
>
> Jo
Using rescue this way will rescue all exceptions, but simply return nil.
Examples:
irb(main):001:0> puts a rescue nil
=> nil
irb(main):002:0> puts "asiodhasd".asdiajsd rescue nil
=> nil
irb(main):003:0> asdi.asdiojas.asidjas.asdihja.asdijasd rescue nil
=> nil
irb(main):004:0>
It's better, as I think Logan was implying, to rescue a specific
exception if you are expecting it. That way, you will see if other
exceptions occur.
Sorry if I misunderstood your reply.
-Justin