Error handling in AppleScript uses
on error. The code which may throw an error goes in the
try block and any error handling code is in the
on error block. The
on error block is closed using
foo is not defined, so throws an error. When an error occurs, the dialog is displayed.
try foo on error display dialog "An error occurred" end try
It is possible to obtain the error message and error number using
on error errormsg number errorno where errormsg and errorno are variable names for the error message and error number.
try foo on error errormsg number errorno display dialog errormsg & errorno end try
The variable foo is not defined.-2753