捕捉错误
AppleScript 中的错误处理使用 try on error 。可能引发错误的代码在 try 块中,任何错误处理代码都在 on error 块中。on error 区块使用 end try 关闭。
foo 未定义,因此抛出错误。发生错误时,将显示该对话框。
try
foo
on error
display dialog "An error occurred"
end try
这是能够得到使用错误消息和错误数量,其中 ERRORMSG 和 errorno 是错误消息和错误编号的变量名。 on error errormsg number errorno ** **
try
foo
on error errormsg number errorno
display dialog errormsg & errorno
end try
变量 foo 未定义。-2753