Error Handling

revIgniter lets you build error reporting into your applications using the handlers described below. In addition, it has an error logging library that permits error and debugging messages to be saved as text files.

Note: By default, revIgniter displays all LiveCode errors. You might wish to change this behavior once your development is complete. You'll find the errorMode setting in the application/config/config.lc file. Disabling error reporting will NOT prevent log files from being written if there are errors.

Error handlers are available globally throughout the application. These do not require loading any libraries or helpers

The following handlers let you generate errors:

rigShowError "message" [, statusCode ]

This handler will display the error message supplied to it using the following error template:

application/errors/errorGeneral.lc

The optional parameter statusCode determines what HTTP status code should be sent with the error.

rigShow404 "page"

This handler will display the 404 error message supplied to it using the following error template:

application/errors/error404.lc

The handler expects the string passed to it to be the file path to the page that isn't found. Note that revIgniter automatically shows 404 messages if controllers are not found.

Note: You can write your own 404 error controller using a routing rule overriding the default 404 error page. This won't affect the rigShow404 handler, which will continue loading the default error404.lc file at application/errors/error404.lc. Please see the URI Routing section of the User Guide.

rigLogMessage "level", "message", "displayError"

This handler lets you write messages to your log files. You must supply one of three "levels" in the first parameter, indicating what type of message it is (debug, error, info), with the message itself in the second parameter and a boolean in the optional third paramater, which indicates if the error should be displayed in an error page. Example:

if tSomeVar = "" then
  rigLogMessage "error", "Some variable did not contain a value."
else
  rigLogMessage "debug", "Some variable was correctly set."
end if

rigLogMessage "info", "The purpose of some variable is to provide some value."

There are three message types:

  1. Error Messages. These are actual errors, such as user errors.
  2. Debug Messages. These are messages that assist in debugging. For example, if a library has been loaded, you could log this as debugging info.
  3. Informational Messages. These are the lowest priority messages, simply giving information regarding some process. revIgniter doesn't natively generate any info messages but you may want to in your application.

Note: In order for the log file to actually be written, the "logs" folder must be writable. In addition, you must set the "threshold" in application/config/config.lc for logging. You might, for example, only want error messages to be logged, and not the other two types. Then set gConfig["logThreshold"] in config.lc to 1. Set the "threshold" to 2 to log debug messages, set it to 3 to log informational messages and set it 4 to log all. If you set it to zero logging will be disabled.

rigDoException Contexts, CurrentFile, CurrentHandler

Try Catch statement error reporting displaying an error page:

try
  put 2 / 0 into tDivision
catch tContexts
  put "errortest.lc" into tCurrentFile
  put "index" into tCurrentHandler
  rigDoException tContexts, tCurrentFile, tCurrentHandler
end try

Where "errortest.lc" is the name of the controller file and "index" is the executing handler.

Note: To send the error output to the browser the error logging threshold in application/config/config.lc must be set to 1 or higher. The rigDoException handler overrides the LiveCode errormode error handling.