Need an example of how to use "try" and "catch"

Bob Sneidar bobs at twft.com
Thu Mar 22 14:30:33 EDT 2012


I use it to determine if there has been an error executing a sequel query for example. All my database calls go inside a try catch statement. If you put it into a repeat loop, you can test to see if perhaps you have been disconnected, or if a runtime error occurred due to a bad query, and then act accordingly, either try to reconnect if disconnected, or bail out gracefully if a runtime error has occurred. 

Bob


On Mar 22, 2012, at 10:33 AM, Michael Doub wrote:

> Does anyone have any guidelines as to when you should use the try and catch structure?   I don't really know when or when not to use it.
> 
> -= Mike
> 
> 
> 
> On Mar 22, 2012, at 1:21 PM, Jim Hurley wrote:
> 
>> Thanks Peter.
>> 
>> The problem now is what do these bloody error numbers translate into.
>> Is the a list somewhere?
>> 
>> When I try:
>> 
>> on mouseUP
>>  try
>> put the cantdelete of me into temp 
>> catch tErr
>> --- if tErr is ??????
>> end try
>> end mouseUP
>> 
>> I get an error of 348,0,0
>> 
>> Jim
>> 
>> 
>> 
>> 
>>> Peter Brigham wrote: 
>>> 
>>> The syntax for the try construction is
>>> 
>>> try
>>>  <command here>
>>> catch tError
>>>  <other commands here>
>>> end try
>>> 
>>> and the error number is put into the variable tError. So the <other commands> could be, eg,
>>> 
>>>  if tError = 314 then
>>>     answer "range error in loading array"
>>>  else if ...
>>>     etc.
>>>  end if
>>> 
>>> -- Peter
>>> 
>>> Peter M. Brigham
>>> 
>>> pmbrig at gmail.com
>>> http://home.comcast.net/~pmbrig
>>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list