Page 1 of 1

Error log for Mobile

Posted: Sun Jul 20, 2014 6:21 pm
by William Jamieson
Hello everyone! I just wanted to see if anyone knew of a way to log errors, or log events in a log file on mobile devices.

I would like to have the system let me know what it is up to on the mobile device. I have found multiple terms for doing it on desktop like using the word "scriptExecutionError," but I searched through the library and there was nothing that was compatible for mobile.

My goal with this is to see what my app is doing right before a) something doesn't function properly or b) it force quits. It would need to build this log in real time and have it saved to a file outside of the app (I think) so that the information is preserved, and may be sent to the cloud for inspection upon restarting the application.

Is there an extension for this? Or does anyone know the best way to do that?

This is an open discussion. Please post any and all thoughts and comments!

Thanks for your interest!

Re: Error log for Mobile

Posted: Sun Jul 20, 2014 9:57 pm
by Mark
Hi,

On iOS, the put command displays text in the console, while in the IDE the text is displayed in the message box.

Kind regards,

Mark

Re: Error log for Mobile

Posted: Mon Jul 21, 2014 11:34 am
by MaxV
From Livecode User Guide:
10.4 Custom Error handling

If you are creating an application that is going to be distributed, you may want to include a method for catching and handling errors. LiveCode provides two such methods. The first is the try/catch control structure. This control structure can be inserted around any routine that you know may encounter problems when in use. For example, you may wish to include this around a routine that reads in a file from disk to handle the case where a corrupted file has been selected. The second method is to write a custom errorDialog routine. Unlike a try/catch control structure, an errorDialog handler is global to your application (or card or stack within an application) and does not provide a mechanism to allow a script that encounters an error to continue. Use this
method to display a custom error dialog when an error occurs that you are unable to predict and report using try/catch.

Using try/catch

Enclose code that may be error prone within a try control structure. The following example shows a routine that opens and reads from a file enclosed in a try statement. If an execution error occurs in any of the statements after the start of the try control structure, the catch clause will be triggered with the details of the error. In the example below we declare a variable someError to contain details of the error.

Code: Select all

try
  open file tFile
  read from file tFile until eof
  close file
  catch someError
  answer "An error occurred reading a file" && someError
end try
Tip: The data returned to the error routine is returned in the internal format that LiveCode uses to display execution errors. To look up the human friendly string associated with a particular error, look at the first item returned against the list of execution errors stored in the LiveCode IDE.

Code: Select all

put line (item 1 of someError) of the cErrorsList of card 1 of stack "revErrorDisplay"
This will only work in the IDE.

If you want to include statements that will be run regardless of whether there has been an error or not, include the statements as part of a finally clause.
To create readable error messages for cases where you anticipate there may be an error, use the throw keyword. For example, if we want to display an error message when the result for opening a file returns something:

Code: Select all

open file tFile
if the result is not empty then throw the result
In the example above, if the file cannot be opened and the result is set, the value of the result will be passed to the catch statement in the someError variable.

Writing a custom errorDialog routine

When an execution error occurs, an errorDialog message is sent. The IDE uses this message to display the execution error dialog. However you can write and include your own custom errorDialog routine. This is useful if you are planning to distribute your application. For example, you could create a stack that transmits the error information directly to your technical support department or displays a custom message on screen. A basic errorDialog routine is shown below:

Code: Select all

on errorDialog pError
  answer "There was an error" && pError
end errorDialog
This routine will also be activated if you use the throw keyword to throw an error (outside of a try/catch control structure).

Re: Error log for Mobile

Posted: Thu Jul 31, 2014 7:57 pm
by William Jamieson
You are absolutely right! Thank you for showing me that. "ErrorDialogue" message will help a lot!

Cheers!

Thanks for the helpful info!

-Will