try
| Syntax |
try statements1 else statements2
|
| Action |
Executes statements1. If an error is encountered, executes statements2. The else clause of the try statement is optional. If it is omitted, an error in the try block will simply cause execution to continue with the following statements.
|
| Examples |
fileloop (f in folder, 1) try file.delete (f) else dialog.notify ("The file " + f + " could not be deleted")
In this example, we ensure that we attempt to delete every file in folder, even if some of them cannot be deleted. file.close (path)
else scriptError (tryError)
Here we use the try statement to ensure that we clean up properly when an error occurs. We then post the same error message that was intercepted. |
| Notes |
When an error occurs, any remaining statements in statements1 are not executed; execution immediately jumps to statements2, if provided, or to the statement following the try block. When an error occurs and statements2 are executed, the variable "tryError" is defined to be the text of the error message that would have been generated by statements1. This special variable is strictly local to the else body; it is not a global, and cannot be referenced except by statements2. Try statements can be nested.
|
| See Also |
scriptError
|