try [on error] [number | from | partial result | to] end[error | try]
Try (* code statements here *) on error errText display dialog "An error:" & errText end try
try represents AppleScript’s
all-important error-trapping capability. If any of the statements
that are enclosed in a
try...end try statement
block raise an error, then AppleScript catches the error and prevents
it from taking down the whole script. After
catches the error (similar to Java’s
try...catch exception-trapping syntax), the script
has the option of adding inside the
try block the
on error followed by any code that
should execute in response to the error.
on error is optional inside of
try statements beginning with AppleScript 1.4.
The program will then resume following the
part of the
try block, as though nothing happened.
AppleScript’s default error behavior is to display
an error message in a dialog box then cancel the running script.
try only catches one error at a time. By using the
on error statement and its numerous parameters,
you can uncover all kinds of details about the error, but you do not
have to use it. In the OS versions previous to Mac OS 9, Script
Editor does not compile a script that includes a
try block without an
This example traps any errors caused by invalid data entered by the
user, and then goes on its merry way without explicitly responding to
try statements can be used inside ...