executes a list of statements, sending any errors to the try control structure to be handled.
# Metadata
Platforms: desktop, server, mobile OS: mac, windows, linux, ios, android Introduced: 1.0 Security:
# Syntax
try statementList [ catch errorVariable errorStatementsList ] [ finally cleanupStatementsList ] end try
# Params
- statementList : The statementList, errorStatementsList, and cleanupStatementsList each consist of one or more valid LiveCode statements. - errorVariable : A valid variable name. - errorStatementsList : - cleanupStatementsList :
# Description
Use the try control structure to execute a series of statements and handle any error messages in the catch section, instead of letting LiveCode display the error window.
**Form:** The try control structure begins with the word try on a single line, followed by a list of LiveCode statements.
The catch section begins with the catch keyword, followed by a parameter name. If any errors occur during execute of the statementList, the error message is placed in the errorVariable parameter, and the errorStatementsList is execute. statements in the errorStatementsList can refer to the value of the errorReport.
The catch section may be followed by an optional finally section. The cleanupStatementsList is execute normally, even if LiveCode encountered an exit or pass statement in the statementList.
The try control structure ends with an end try statement.
Each of the statements in the statementList is execute normally, just as though the statementList were not in a try control structure, except that any errors that would normally display an error window instead trigger the catch section. This happens even if the error is in another handler that's call from within the try control structure.
The statements in the catch section are execute only if an error occurs. Only errors that would normally display the error window are handled by the catch section. If the error would not normally display the error window--for example, errors when opening a file with the open file command --it doesn't trigger the catch section.
The statements in the finally section are execute whether or not there is an error. Since the finally section is always execute even if the statementList contains an exit or pass statement, it can be used for final cleanup actions such as deleting variables. The finally section is an optional part of the try control structure.
>*Note:* The try control structure is implemented internally as a > command and appears in the commandNames.
# Tags
# See