Language Guide

CHAPTER 7
Control Statements
208 Try Statements
offendingObjectVariable (an identifier) is a parameter variable for the reference
to the application or object that caused the error (a reference). You use this
parameter variable to refer to the object that caused the error within the
error handler.
resultListVariable (an identifier) is a parameter variable for the results for objects
that were handled before the error occurred. Its value is a list that can contain
values of any class. You use this parameter variable to refer to the partial
results within the error handler. This parameter applies only to commands that
return results for multiple objects. For example, if an application handles the
command get words 1 thru 5 and an error occurs when handling word 4,
the partial result parameter contains the results for the first three words.
expectedTypeVariable (an identifier) is a parameter variable for the expected
value class (a class identifier)—that is, the value class to which AppleScript
was attempting to coerce the value of offendingObjectVariable. If an application
receives data of the wrong class and cannot coerce it to the correct class, the
value of this parameter variable is the class of the coercion that failed. (The
example at the end of this definition demonstrates how this works.)
variable is an identifier for either a global variable or a local variable that can be
used in the handler. The scope of a local variable is the handler. You cannot
refer to a local variable outside the handler. The scope of a global variable can
extend to any other part of the script, including other handlers and script
objects. For detailed information about the scope of local and global variables,
see “Scope of Script Variables and Properties,” which begins on page 252.
EXAMPLES
The following Try statement provides an error handler for the Choose File
command. (For a complete description of the Choose File command, see the
AppleScript Scripting Additions Guide.) The Choose File command returns an
error if the user clicks the Cancel button in the Choose File dialog box. The
error handler gives the user a chance to continue if an error occurs.
try
choose file
set fileName to result