Error handler code

Does anybody have good error handler which checks various things when error happens? Like is hd full/does x file exist/is network on/…

Hi,

Do you have anything specific in mind? I’m very new, but I use this for checking files…

set thefile to "HDname:username:destkop:filename.ext"
Tell application "Finder"
if file thefile exists then
dothis()
else
dosomethingelse()
end if
end tell

or for a mounted volume try this…it’s probably not the most effective way, but I’m still learning the in’s and out’s of AS…

set servername to "ServerVolumeName:"
try
	set servername to servername as alias
on error
	try
		mount volume "afp://Serveraddress/Volumename" as user name "username" with password "password"
	on error
		display dialog "uh oh"
	end try
end try

I don’t have one, cirno, but if I needed one, I’d start with the kinds of errors likely to crop up. See these references for AppleScript Errors, and Apple Event Errors:

http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScript.10d.html

http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScript.10b.html

Then, sprinkled throughout your script where failures might occur:

try
	set D to "path to folder that's not there"
	tell application "Finder" to set f to files of entire contents of D
on error errTxt number errNum
	Recover(errTxt, errNum)
end try

on Recover(Etxt, ENum)
	
	-- do something with the message or the number or both
	
end Recover