On error, relaunch script

My scripts gets lots of errors because i dont use onerror…try…enderror. I want to create simple error handler that simply relaunches this same script when any error occurs. Also where can i find error codes explained?

Hi cirno

IMHO it would be better to implement a fair error handling.
Otherwise, in worst case you get an infinite loop of your script restarting continuously

You can catch an error and display error number and message with

try
– do something
on error e number n
display dialog "Error number " & (n as string) & " occured " & return & quote & e & quote
end try

Further to Stefan’s good advice, if you want to repeat an error-prone operation, then you should limit the tries and announce success or failure:


property Tries : 0

on run
	repeat while Tries < 4
		if doErrorProneThing() then
			display dialog "Done"
			return
		else
			set Tries to Tries + 1
			doErrorProneThing()
		end if
	end repeat
	display dialog "Process Failed after " & Tries & " tries" --> 4 tries in this case
end run

to doErrorProneThing()
	try
		error -- comment out this line to test success
		return true
	on error
		return false
	end try
end doErrorProneThing