On 6/26/2014 12:23 PM, Peter Haworth wrote: > On Thu, Jun 26, 2014 at 8:22 AM, Richard Gaskin <ambassa...@fourthworld.com> > wrote: > >> Is there a simple rule that would allow scripters to understand when >> try-catch is necessary and when the result should be checked instead? >> >> If not, should there be? >> >> Or perhaps better yet, could error handling be made uniform, maybe as part >> of the Open Language initiative? If so, what would it look like? >> > Personally, I think error handling should be made uniform. As you say, > sometimes try/catch is required, other times the result must be checked and > sometimes "it" must be checked. Then there's the different ways errors are > reported by the database library commands. >
Try - Catch functionally is present many programming languages for a very different purpose than general error reporting. Language commands and functions that can detect, trap, and report an error, should return appropriate error information that the programmer can check for. LC generally does this via "the result", the returned value of a function itself (an empty return value from some functions can equal an error condition, or a function may return an error message), or "it" - and among these, improved consistency would be a nice improvement. However, no language can really prevent programming error or error based on unexpected inputs - i.e. add "fred" to tVar - that results in an execution error. Try/Catch serves as a tool in modern programming languages to allow a programmer to catch any UNEXPECTED execution error and handle it in some controlled way. Both mechanism can be used together. In the example below, if tInput contained text ("fred") rather than a number or if either "someFunction" or "someCommand return errors, the entire block of code has a graceful exit. try add tInput to tVar put someFuntion(tVar) into tVar2 if tVar2 is empty throw error someCommand tVar2 if the result begins with "error" then throw error catch tError -- controlled exit here end try _______________________________________________ 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