kill applescript automatically when it fails?

Hi

I need to kill a apple script when it fail automatically. (no one may be around for 5 days when the script failed, also the script may get call by other automated shell script so we have to kill it if it failed) Any idea?

How I do this or similar functions is to use the try on error and a handler that will quit.
Wrap the part of relevant code with a:

try
	-- your commands go here that may be causing the error or timeouts
on error errMsg number errNum
	-- on error code goes here
  if errNum = 128 then
     try    
           doQuit()
     on error number errNum
     quit  
     end try     
  end if
end try
on doQuit()
	quit
end doQuit

Or


on quit
	try
		--any extra commands go here, like trying to save a file
	on error
	end try
	continue quit
end quit