Using 'try'

Graham Samuel livfoss at mac.com
Thu Apr 13 18:01:29 EDT 2006


On Thu, 13 Apr 2006 13:36:23 -0700, Mark Wieder  
<mwieder at ahsoftware.net> wrote:
>
> Graham-
>
> Thursday, April 13, 2006, 12:28:52 AM, you wrote:
>
>
>> In the very interesting discussion on Custom Properties, Mark Wieder
>> introduced this example
>>
>
>
>>> setProp NewValue pValue
>>>   try
>>>     if pValue < 0 then
>>>       set the foreColor of me to "red"
>>>     else
>>>       set the foreColor of me to empty
>>>     end if
>>>   end try
>>>   put pValue into me
>>> end NewValue
>>>
>
>
>> I think I get the idea, but Mark, why did you use 'try'? It would not
>>
>
> David Burgun as provided the longer-winded explanation (and a great
> one at that - not meant as putting it down), but basically the "try"
> construct here lets me set the field to empty without running into a
> runtime error. Without the try the code would give me an error on the
> first line if pValue is empty, since it would try to execute
>
> if < 0 then
>
> Putting the code inside a try construct lets me ignore the error that
> results from trying to execute an illegal statement and move on to the
> next line of executable code after the end try.

Thanks Mark, that really is very clear (and very clever). I'm storing  
it up for use later...

Thanks for all who clarified this for me

Graham


------------------------------------------------------------------------ 
---
Graham Samuel / The Living Fossil Co. / UK and France




More information about the use-livecode mailing list