Language Guide

CHAPTER 7
Control Statements
210 Try Statements
Signaling Errors in Scripts 7
A script can signal an error—which can then be handled by an error handler—
with the Error command. This allows scripts to define their own messages for
errors that occur within the script.
Error 7
The Error command signals an error in a script.
SYNTAX
error ¬
[ errorMessage ] ¬
[ number errorNumber ] ¬
[ from offendingObject ] ¬
[ partial result resultList
[ to expectedType ]
where
errorMessage is an expression, usually a string, describing the error. Although
this parameter is not required, you should provide descriptive expressions
for errors wherever possible (a string is the best way to inform the user of an
error), and you should always provide an expression if you do not include a
number parameter. If you do not include an error expression, an empty string
("") is passed to the error handler.
errorNumber is the error number for the error. You do not have to include an
error number, but if you do, the number must not be any of the error numbers
listed in Appendix C, “Error Messages.” In general, positive numbers from 500
to 10,000 do not conflict with error numbers for AppleScript, the Operating
System, or Apple events. If you do not include a number parameter, the value
-2700 is passed to the error handler.
offendingObject is a reference to the object, if any, that caused the error. If you
provide a partial reference, AppleScript completes it using the value of the
default object.