On Feb 12, 2013 7:57 PM, <sto.mar / web.de> wrote:
>
> Am 11.02.2013 22:28, schrieb Matthew Kerwin:
>
>> sto.mar wrote in post #1096319:
>>>
>>> Hmmm... very dangerous.
>>>
>>> That would catch all kinds of exceptions, not only the NameError:
>>>
>>>     a = []
>>>     b = a + 1
>>>     # => TypeError: can't convert Fixnum into Array
>>>
>>> vs.
>>>
>>>     a = []
>>>     b = a + 1 rescue 99
>>>     b  # => 99
>>
>>
>> Back in the olden days, MOO code had the following:
>>
>>      `x + 1 ! E_TYPE';
>> ... returns (x+1) or E_TYPE, or raises E_VARNF.
>>
>>      `x.y ! E_PROPNF, E_PERM => 17'
>> ... returns x.y if x is an object and x.y is a readable property;
>> returns 17 if x is an object but x.y is not defined or
>> not readable; or raises something else (like E_VARNF or E_INVIND)
>>
>>      `1 / 0 ! ANY';
>> ... returns E_DIV
>>
>> I liked being able to explicitly trap a certain class of exception, and
>> either return the exception itself or a default value.
>>
>> Additionally it had try/catch blocks.
>>
>> [1] http://files.moo.ca/1/1/7/ProgrammersManual_26.html#SEC26
>>
>
> b = a + 1  rescue $!
> b  # => #<NameError: undefined local variable or method `a' for
main:Object>
>

+1 I've been writing so much perl lately I should have remembered the magic
globals...

There's still no way to trap a class (or classes) of exception without
writing a begin-rescue block, is there? I'm just asking, not complaining.