From: Matthew Kerwin Date: 2013-02-13T05:57:44+09:00 Subject: Re: elegant way to determine if something is defined --bcaec554d43406569704d58ce2dd Content-Type: text/plain; charset=ISO-8859-1 On Feb 12, 2013 7:57 PM, 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 # => # > +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. --bcaec554d43406569704d58ce2dd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Feb 12, 2013 7:57 PM, <sto.mar@w= eb.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 NameErr= or:
>>>
>>> =A0 =A0 a =3D []
>>> =A0 =A0 b =3D a + 1
>>> =A0 =A0 # =3D> TypeError: can't convert Fixnum into Arr= ay
>>>
>>> vs.
>>>
>>> =A0 =A0 a =3D []
>>> =A0 =A0 b =3D a + 1 rescue 99
>>> =A0 =A0 b =A0# =3D> 99
>>
>>
>> Back in the olden days, MOO code had the following:
>>
>> =A0 =A0 =A0`x + 1 ! E_TYPE';
>> ... returns (x+1) or E_TYPE, or raises E_VARNF.
>>
>> =A0 =A0 =A0`x.y ! E_PROPNF, E_PERM =3D> 17'
>> ... returns x.y if x is an object and x.y is a readable property;<= br> >> 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)<= br> >>
>> =A0 =A0 =A0`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 =3D a + 1 =A0rescue $!
> b =A0# =3D> #<NameError: undefined local variable or method `a&#= 39; for main:Object>
>

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

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

--bcaec554d43406569704d58ce2dd--