Re: Need an example of how to use try and catch
Mark, Yes! I agree with you about throw. Do you, or dose anyone, have an example that shows the use of the throw command in conjunction with the try-catch structure? Jim Message: 4 Date: Thu, 22 Mar 2012 22:33:42 -0700 From: Mark Wieder mwie...@ahsoftware.net To: use-livecode@lists.runrev.com Subject: Re: Need an example of how to use try and catch Message-ID: 33780499187.2012033...@ahsoftware.net Content-Type: text/plain; charset=us-ascii Jacque- Thursday, March 22, 2012, 10:19:59 PM, you wrote: P.S. There really ought to be an illustration of the try-catch syntax in the dictionary. I just looked, and I'm amazed there isn't. Myabe you could add a user note. Yeah - the throw command should be mentioned there as well. -- -Mark Wieder mwie...@ahsoftware.net ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
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 On Thu, Mar 22, 2012 at 4:10 PM, Bob Sneidar b...@twft.com wrote: When you are in a standalone, a runtime error that would halt execution might be fatal. Try/Catch allows you to handle the error gracefully without presenting the user with an ugly dialog and a QTD afterwards. You can politely inform the user that something has gone wrong and you have to exit the application, after tidying things up a bit if necessary. Databases can just go away sometimes, like the IT guy deciding it's time to update the servers and restart them while the user is working late on an important project. Setting a repeat loop around a try/catch construct allows you to attempt a reconnect a certain number of times, or present the user with a Retry/Cancel dialog, allowing you to clean up and exit gracefully if necessary. As a case in point, I was having a problem with a low level broadcast storm which was causing the uplinks on our switches to reset (they are designed to do that). Anyone who uses Microsoft SQL knows this can be fatal, depending on how the software is written. Our accounting software was not very well written, and as a result, the end user was subject to a never ending stream of error dialogs allowing a cancel, retry or abort! None of them exited gracefully. ICK!! Had the developer accounted for the possibility that the user could be disconnected from the database, and provided a graceful exit, my reputation would not now be so tarnished, because they all blamed me of course. :-) To the accounting girl's credit however, they did make me brownies when I found the source of the broadcast storm and fixed it. Bob On Mar 22, 2012, at 3:31 PM, Pete wrote: Sorry to keep this thread going but I'm trying to figure out if I should be using try/catch more, particularly for database calls. As far as I know, you can tell if any of the standard rev db calls fail by checking their returned value or the result. Are there circumstances where that's not the case or does SQLYoga silent about errors? I have experienced silent datagrid problems that were only revealed by enclosing the datagrid access statements in try/catch. Pete ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode -- Pete Molly's Revenge http://www.mollysrevenge.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
The syntax is there at the top but it's not formatted -- tabs or space-runs between the lines instead of cr's. Looks like a problem in the dictionary stack with displaying the text from the customprop. If it were displayed properly you could see the structure, and then the commentary would explain things pretty well. -- Peter Peter M. Brigham pmb...@gmail.com http://home.comcast.net/~pmbrig On Mar 23, 2012, at 1:19 AM, J. Landman Gay wrote: On 3/22/12 11:59 PM, Jim Hurley wrote: LC is an English muffin. So many nooks and crannies. I like that. :) P.S. There really ought to be an illustration of the try-catch syntax in the dictionary. I just looked, and I'm amazed there isn't. Myabe you could add a user note. -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Need an example of how to use try and catch
The dictionary needs an example of how the try command is used to catch an error. Anyone have an illustration? For example, suppose one wanted to catch an error in the statement: put the {some built-in property of an object] of button soAndso into tProp Where the built in property may not exist.How would one catch the error and perhaps proceed on the basis of the particular error message? Thanks, Jim ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
try put foo into myVar put the value of myVarr catch theError, theNum -- breakpoint answer theNum cr line1 of theError as sheet exit to top end try Is that what you mean? Bob On Mar 22, 2012, at 8:33 AM, Jim Hurley wrote: The dictionary needs an example of how the try command is used to catch an error. Anyone have an illustration? For example, suppose one wanted to catch an error in the statement: put the {some built-in property of an object] of button soAndso into tProp Where the built in property may not exist.How would one catch the error and perhaps proceed on the basis of the particular error message? Thanks, Jim ___ use-livecode mailing list use-livecode@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
On Mar 22, 2012, at 11:33 AM, Jim Hurley wrote: The dictionary needs an example of how the try command is used to catch an error. Anyone have an illustration? For example, suppose one wanted to catch an error in the statement: put the {some built-in property of an object] of button soAndso into tProp Where the built in property may not exist.How would one catch the error and perhaps proceed on the basis of the particular error message? example: try put sha1digest(tString) into tDigest catch tErr put md5digest(tString) into tDigest -- if version 4.5.3 end try -- Peter Peter M. Brigham pmb...@gmail.com http://home.comcast.net/~pmbrig ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
Bob, Yes that would be fine, except that I get a compilation error at the line: catch theError, theNum RR says: (try: not a command), char 7 Jim Bob Sneidar wrote: try put foo into myVar put the value of myVarr catch theError, theNum -- breakpoint answer theNum cr line1 of theError as sheet exit to top end try Is that what you mean? Bob ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
On Mar 22, 2012, at 11:33 AM, Jim Hurley wrote: For example, suppose one wanted to catch an error in the statement: put the {some built-in property of an object] of button soAndso into tProp Where the built in property may not exist.How would one catch the error and perhaps proceed on the basis of the particular error message? Note that getting the customProp of an object where the property doesn't exist will return empty but won't trigger any error. If you want to catch this then don't use a try statement, do something like put the myProperty of btn x into tProp if tProp empty then -- do something with the property else -- handle error here end if -- Peter Peter M. Brigham pmb...@gmail.com http://home.comcast.net/~pmbrig ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
On Mar 22, 2012, at 12:22 PM, Jim Hurley wrote: Bob, Yes that would be fine, except that I get a compilation error at the line: catch theError, theNum RR says: (try: not a command), char 7 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 pmb...@gmail.com http://home.comcast.net/~pmbrig ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
You're getting an error because the catch part of try takes only 1 parameter - the variable that holds the error - not two as in the script. Also, as noted by Peter, the try statement doesn't help you with the specific example you used since getting a non-existant custom property doesn't cause an error. I've sometimes wished there was a preference similar to the Strict Compilation Mode to deal with that. Pete On Thu, Mar 22, 2012 at 9:22 AM, Jim Hurley jhurley0...@sbcglobal.netwrote: Bob, Yes that would be fine, except that I get a compilation error at the line: catch theError, theNum RR says: (try: not a command), char 7 Jim Bob Sneidar wrote: try put foo into myVar put the value of myVarr catch theError, theNum -- breakpoint answer theNum cr line1 of theError as sheet exit to top end try Is that what you mean? Bob ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode -- Pete Molly's Revenge http://www.mollysrevenge.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
Whoops maybe the second argument is not valid. On Mar 22, 2012, at 9:22 AM, Jim Hurley wrote: Bob, Yes that would be fine, except that I get a compilation error at the line: catch theError, theNum RR says: (try: not a command), char 7 Jim Bob Sneidar wrote: try put foo into myVar put the value of myVarr catch theError, theNum -- breakpoint answer theNum cr line1 of theError as sheet exit to top end try Is that what you mean? Bob ___ use-livecode mailing list use-livecode@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
Also I forgot the finally part try -- some statements catch theError -- do some stuff if there is an error finally -- do some other stuff no matter what end try On Mar 22, 2012, at 9:22 AM, Jim Hurley wrote: Bob, Yes that would be fine, except that I get a compilation error at the line: catch theError, theNum RR says: (try: not a command), char 7 Jim Bob Sneidar wrote: try put foo into myVar put the value of myVarr catch theError, theNum -- breakpoint answer theNum cr line1 of theError as sheet exit to top end try Is that what you mean? Bob ___ use-livecode mailing list use-livecode@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
It does give an error here. I get the error message: button Button: execution error at line n/a (Object: object does not have this property) Jim Message: 2 Date: Thu, 22 Mar 2012 09:55:20 -0700 From: Pete p...@mollysrevenge.com To: How to use LiveCode use-livecode@lists.runrev.com Subject: Re: Need an example of how to use try and catch Message-ID: CABx6j9=UY=3n6-vjpmxastopezh0ewj6kpopa01vxcxke3t...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 You're getting an error because the catch part of try takes only 1 parameter - the variable that holds the error - not two as in the script. Also, as noted by Peter, the try statement doesn't help you with the specific example you used since getting a non-existant custom property doesn't cause an error. I've sometimes wished there was a preference similar to the Strict Compilation Mode to deal with that. Pete * ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
On 3/22/12 12:21 PM, Jim Hurley wrote: Thanks Peter. The problem now is what do these bloody error numbers translate into. Is the a list somewhere? The list is explained in the errordialog entry in the dictionary. You can retrieve the list with the line of script the dictionary provides. There is also this utility for manual lookups: http://dl.dropbox.com/u/23431607/LiveCode%20Error%20Lookup.livecode.zip -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
On Mar 22, 2012, at 1:11 PM, Jim Hurley wrote: It does give an error here. I get the error message: button Button: execution error at line n/a (Object: object does not have this property) Sounds as if you're trying to get a built-in property that doesn't apply to that type of object. If you try to get the scroll of a button, you'll get an error. If you try to get the mycustomProp of a button and you've never set the mycustomProp of that button to anything (so it doesn't exist), you'll get empty with no error message. -- Peter Peter M. Brigham pmb...@gmail.com http://home.comcast.net/~pmbrig ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
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@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
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? Jacque posted this two days ago: On 3/20/12 12:37 PM, Ralph DiMola wrote: OK, I give up. How do you translate error number into descriptive text? There's a plugin that Richard Gaskin and I developed. I've been trying to upload it to RevOnline for some time but it won't let me. Until that gets fixed, anyone who wants it can grab it from my Dropbox: http://dl.dropbox.com/u/23431607/LiveCode%20Error%20Lookup.livecode.zip The advantage of this little stack over a static resource (besides being free) is that it dynamically loads the error list from the currently running copy of LiveCode. That means it will never go out of date, and will change depending on which version of LiveCode you open it in. There's a second card that's intended for use with debugging iOS errors copied from the Console app. There's an Info button in the stack for more details. It hasn't been thoroughly tested but I've been using it for some time without any problems. The scripts are open, so you can change it if you want. If you do, please let me know so I can update the master copy. - 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 first item is the error number, second item is the line number of the script where it hangs, and the third is the character number in the line. Error 348 is: 348 Object: object does not have this property Not sure what line 0 char 0 means. Maybe someone else knows? -- Peter Peter M. Brigham pmb...@gmail.com http://home.comcast.net/~pmbrig ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
RE: Need an example of how to use try and catch
I second this! Ralph DiMola IT Director Evergreen Information Services rdim...@evergreeninfo.net Also, as noted by Peter, the try statement doesn't help you with the specific example you used since getting a non-existant custom property doesn't cause an error. I've sometimes wished there was a preference similar to the Strict Compilation Mode to deal with that. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
On Mar 22, 2012, at 1:32 PM, J. Landman Gay wrote: On 3/22/12 12:21 PM, Jim Hurley wrote: Thanks Peter. The problem now is what do these bloody error numbers translate into. Is the a list somewhere? The list is explained in the errordialog entry in the dictionary. You can retrieve the list with the line of script the dictionary provides. There is also this utility for manual lookups: http://dl.dropbox.com/u/23431607/LiveCode%20Error%20Lookup.livecode.zip Or, here's something for your library, so you can call it from a script or from the message box: function expandError tErr repeat for each line e in tErr put item 1 of e into errNbr put item 2 of e into tLineNbr put item 3 of e into tCharNbr put errNbr (line tLineNbr , char tCharNbr ): \ line errNbr of the cErrorsList of card 1 of stack revErrorDisplay \ into tErrMsg put tErrMsg cr after errorlist end repeat if char -1 of errorlist = cr then delete char -1 of errorlist return errorlist end expandError -- Peter Peter M. Brigham pmb...@gmail.com http://home.comcast.net/~pmbrig ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
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@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@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
Interesting, never thought of that. Is there an advantage to doing that over just issuing the database call and checking for an error right after? I've mostly thought of try/catch for as a debugging tool. I also use it any place where I put together a command in a variable and execute the command with a do statement. Pete On Thu, Mar 22, 2012 at 11:30 AM, Bob Sneidar b...@twft.com wrote: 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@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@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode -- Pete Molly's Revenge http://www.mollysrevenge.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
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. Here's another use (and apropos a different thread here) In order to recreate a control you'd want to 1. get the list of properties and their values 2. create a new control of the same type 3. set each of the properties to the original value One problem with this is that some properties are read-only, and some can only be applied to the parent object (can't set the rect of a card, for example). So I do something like repeat for each element tProp in tPropertyArray try set the tProp of tNewControl to tPropertyArray[tProp] catch e -- just ignore the error here end try end repeat -- Mark Wieder ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
No advantage per se, but I use sqlYoga and the only way to determine what went wrong is in a try catch statement as the libSQLYoga stack is locked. Bob On Mar 22, 2012, at 11:49 AM, Pete wrote: Interesting, never thought of that. Is there an advantage to doing that over just issuing the database call and checking for an error right after? I've mostly thought of try/catch for as a debugging tool. I also use it any place where I put together a command in a variable and execute the command with a do statement. Pete On Thu, Mar 22, 2012 at 11:30 AM, Bob Sneidar b...@twft.com wrote: 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@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@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode -- Pete Molly's Revenge http://www.mollysrevenge.com ___ use-livecode mailing list use-livecode@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
RunRev was thinking of calling the try construct, TryAndDontStopDeadInYourTracksUponAnError but they opted for the shorter version. ;-) Bob On Mar 22, 2012, at 1:08 PM, Mark Wieder wrote: 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. Here's another use (and apropos a different thread here) In order to recreate a control you'd want to 1. get the list of properties and their values 2. create a new control of the same type 3. set each of the properties to the original value One problem with this is that some properties are read-only, and some can only be applied to the parent object (can't set the rect of a card, for example). So I do something like repeat for each element tProp in tPropertyArray try set the tProp of tNewControl to tPropertyArray[tProp] catch e -- just ignore the error here end try end repeat -- Mark Wieder ___ use-livecode mailing list use-livecode@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@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
I have been using the try/catch idiom for years. I like the structure it gives my code - visually it makes it very clear where I am expecting problematic sections to be. I rarely use 'finally'. However the problem has always been with interpreting the error codes that arise. For years I got round that by incorporating Mark Schonewille's errorLib in my stacks. Like you, I find that sqlYoga really needs try/catch. I did see somewhere else that Trevor recommended having some specific error handler implemented, but for me just wrapping the calls that go to the database in try/catch solves the problem. Bernard On Thu, Mar 22, 2012 at 8:25 PM, Bob Sneidar b...@twft.com wrote: No advantage per se, but I use sqlYoga and the only way to determine what went wrong is in a try catch statement as the libSQLYoga stack is locked. Bob ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
The following script will provide a start in finding all the property values of a given object, in this case the button button It starts with the propertynames which is a list of ALL built-in property names in LC. It then attempts to put the value of each of these properties for the given object. If the attempt was successful, it goes into the object property list, otherwise not. on mouseUp put the propertynames into tProps repeat for each line tLine in tProps put into tErr try put the tLine of button button into tPropVal catch tErr put tLine cr after tOmits next repeat end try if tPropVal is not empty then put tLine tab tPropVal cr after tSaves end repeat put tSaves into field saves put tOmits into field omits end mouseUp ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
When you are in a standalone, a runtime error that would halt execution might be fatal. Try/Catch allows you to handle the error gracefully without presenting the user with an ugly dialog and a QTD afterwards. You can politely inform the user that something has gone wrong and you have to exit the application, after tidying things up a bit if necessary. Databases can just go away sometimes, like the IT guy deciding it's time to update the servers and restart them while the user is working late on an important project. Setting a repeat loop around a try/catch construct allows you to attempt a reconnect a certain number of times, or present the user with a Retry/Cancel dialog, allowing you to clean up and exit gracefully if necessary. As a case in point, I was having a problem with a low level broadcast storm which was causing the uplinks on our switches to reset (they are designed to do that). Anyone who uses Microsoft SQL knows this can be fatal, depending on how the software is written. Our accounting software was not very well written, and as a result, the end user was subject to a never ending stream of error dialogs allowing a cancel, retry or abort! None of them exited gracefully. ICK!! Had the developer accounted for the possibility that the user could be disconnected from the database, and provided a graceful exit, my reputation would not now be so tarnished, because they all blamed me of course. :-) To the accounting girl's credit however, they did make me brownies when I found the source of the broadcast storm and fixed it. Bob On Mar 22, 2012, at 3:31 PM, Pete wrote: Sorry to keep this thread going but I'm trying to figure out if I should be using try/catch more, particularly for database calls. As far as I know, you can tell if any of the standard rev db calls fail by checking their returned value or the result. Are there circumstances where that's not the case or does SQLYoga silent about errors? I have experienced silent datagrid problems that were only revealed by enclosing the datagrid access statements in try/catch. Pete ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
Or - this can be applied to a night out clubbing - try put myBestPickupLine into myMouth catch theResponse If theResponse is not negative -- Oh yeah! set luckynight to true else put wittingComback into myMouth move body to new location finally if not luckynight then goHomeAlone end try Sorry, it's just too obvious… Tim ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
Jacque, Thanks. LC is an English muffin. So many nooks and crannies. Jim P.S. There really ought to be an illustration of the try-catch syntax in the dictionary. Message: 5 Date: Thu, 22 Mar 2012 12:32:01 -0500 From: J. Landman Gay jac...@hyperactivesw.com To: How to use LiveCode use-livecode@lists.runrev.com Subject: Re: Need an example of how to use try and catch Message-ID: 4f6b6211.3070...@hyperactivesw.com Content-Type: text/plain; charset=ISO-8859-1; format=flowed On 3/22/12 12:21 PM, Jim Hurley wrote: Thanks Peter. The problem now is what do these bloody error numbers translate into. Is the a list somewhere? The list is explained in the errordialog entry in the dictionary. You can retrieve the list with the line of script the dictionary provides. There is also this utility for manual lookups: http://dl.dropbox.com/u/23431607/LiveCode%20Error%20Lookup.livecode.zip -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
On 3/22/12 11:59 PM, Jim Hurley wrote: LC is an English muffin. So many nooks and crannies. I like that. :) P.S. There really ought to be an illustration of the try-catch syntax in the dictionary. I just looked, and I'm amazed there isn't. Myabe you could add a user note. -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Need an example of how to use try and catch
Jacque- Thursday, March 22, 2012, 10:19:59 PM, you wrote: P.S. There really ought to be an illustration of the try-catch syntax in the dictionary. I just looked, and I'm amazed there isn't. Myabe you could add a user note. Yeah - the throw command should be mentioned there as well. -- -Mark Wieder mwie...@ahsoftware.net ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode