I need a workaround for error message

Can you tell a script to ignore a particular error message? Thanks.

Hi,

Your message is a bit sparse on information, but would this do it?

try
	-- The original code that throws an error
on error
	-- Alternative code to run instead
end try

Best wishes

John M

Don’t know what program you are getting this error message in but here is something I use sometimes.

tell application "System Events"
	tell process "App name here"
		if exists window "Title of error message window here" then
			delay 1
			key code 36  --the RETURN key to ok the dialog
			--OR
			keystroke "." using command down  --to cancel the dialog
		end if
	end tell
end tell

Further to John M’s reply, the ‘on error’ section of a ‘try’ block can take parameters representing the error text and the error number. There are two ways you could use this to exclude a particular error.

  1. You could supply variables to catch the message and number returned by the error. If either (preferably the number) matches the error you want to ignore, do nothing; otherwise regenerate the error. This is useful when you want to give special treatment to more than one kind of error:
try
	-- Deliberate gaff that throws error number -1728 ("Can't get || of {}.")
	|| of {}
on error errMsg number errNum
	if (errNum is not -1728) then error errMsg number errNum
end try
  1. If you only want to catch one particular error, you could use its error number and/or message in the ‘on error’ line so that only it was caught. Any other errors would go ahead as if the ‘try’ block wasn’t there:
try
	-- Deliberate gaff that throws error number -1728 ("Can't get || of {}.")
	|| of {}
on error number -1728
	-- Do nothing.
end try

It’s generally better to test against the error number (if you know it) rather than the message, as the latter will vary according to the user’s preferred language and the actual value(s) that caused the error.