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

Bob Sneidar bobs at twft.com
Fri Mar 23 14:04:20 EDT 2012


Hi Pete. 

I am not saying that try/catch is necessary when using revDB, but it certainly is when using sqlYoga, or any other plugin that is a locked stack that can generate errors. I would use try catch anyway because I am used to it, and if I am using it in certain places, then for consistency I want to use it throughout. 

Another advantage of try catch is the ability to encompass a series of statements which may generate an error condition, and you don't have to check for an error after each statement. Also, and I may have mentioned this, I find it more elegant to issue a breakpoint in the catch section and go directly to the debugger, rather than be confronted with the runtime error dialog and click Debug. 

Finally as someone else mentioned, some things fail silently. I have made calls to sqlYoga outside a try catch control structure which did not pop a runtime error dialog but did stop program execution. In these cases I believe a try catch control structure will catch the error and allow you to deal with it. 

Bob


On Mar 23, 2012, at 10:34 AM, Pete wrote:

> Bob,
> Maybe I'm missing something but you seem to be saying there are some
> database errors that can only be detected by using try/catch, not by
> checking the result or the "revdberr" string.
> 
> Taking your example of a database going away, I just created a small db,
> opened it in LC, then deleted the db file.  Any further accesses to the db
> in LC came back with an error without using try/catch, so I'm not
> understanding why a try/catch is necessary.
> 
> Not saying try/catch might not be necessary, just trying to understand if I
> need to start using that approach.  My test was done using sqlite so maybe
> other SQL variants is where try/catch is needed or perhaps it's due to your
> use of SQLYoga.
> 
> Pete





More information about the use-livecode mailing list