Meaningful and verbose error messages in LiveCode

Richard Gaskin ambassador at fourthworld.com
Thu Nov 20 12:25:50 EST 2014


Bob Sneidar wrote:

 >> On Nov 20, 2014, at 08:26 , Richard Gaskin wrote:
 >>
 >> Bob Sneidar wrote:
 >>
 >> > In FoxPro you could simply create a handler which got triggered by
 >> > errors then check an internal code for what the most recent error
 >> > was, then make a switch statement to handle all the pertinent
 >> >errors for your project.
...
 >> That's pretty much what LiveCode offers with the errorDialog message.
 >
 > Oh cool! I asked this same thing years ago, and got back from
 > everyone, “Just use try/catch.”

Try/catch is also useful, but for different purposes.

Sometimes try/catch is necessary, since the engine isn't yet smart 
enough with some commands to be able to attempt an operation and fail 
gracefully if it doesn't work out.

For example, if you try to open a file that doesn't exist, you can just 
check "the result" after your "open file" statement and you'll know 
whether it worked out or not.

But as an example of a more immediate-fail condition, if you try to 
decompress non-compressed data you'll never get a chance to check "the 
result" because that particular operation will always throw a script 
error the moment it fails.

With those immediate-thrown-error operations try/catch can be useful 
because it causes the engine to bypass the normal throwing of the error 
message so that you can catch it and handle it more gracefully.

The errorDialog is what's sent in those conditions, so while it can be 
very useful for providing feedback to the user, it can't help you 
recover the operation - at that point graceful degradation is no longer 
an option, since the engine has already determined that normal operation 
is beyond its abilities, and the best it can do is report the error 
condition and exit the routine.

Try/catch can be more work to handle, but in some contexts may provide 
the opportunity for graceful degradation not otherwise possible if the 
error wasn't caught there.

It may be helpful to think of try/catch as an alternative to 
errorDialog, for those cases where you're in a position to provide more 
graceful alternatives for the user than simply halting execution.

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the use-livecode mailing list