Ignore error and continue

set thelist to {}
tell application "System Events"
	set {name:theApp, bundle identifier:theIdentifier} to (get 1st application process whose frontmost is true)
end tell
	repeat with i from 2 to 10
		set documentRecords to (do shell script "defaults read " & theIdentifier & " NSRecentDocumentRecords")
		set {TID, text item delimiters} to {text item delimiters, "<"}
		set alis to text item i of documentRecords
		set text item delimiters to ">"
		set alis to text item 1 of alis
		set text item delimiters to space
		set alis to text items of alis
		set text item delimiters to ""
		set alis to (run script "«data alis" & (alis as text) & "»")
		set text item delimiters to TID
		set alis to alis as text
		set end of thelist to alis
	end repeat
	tell me to activate
	set chooseFile to (choose from list thelist with title "Open Recent" with prompt "Choose File(s):" with multiple selections allowed)
	set theresult to the result
	if theresult is not false then
		repeat with aitem in theresult
			tell application theApp
				open aitem
			end tell
		end repeat
	end if
on error e
	tell me to activate
	display dialog e
end try

Frequently, I get errors like “Can’t get item 7 of…” because the file may have been moved/deleted by me. I want that in such cases, the remaining items (i.e. items 1 to 6 and 8 to 9/10) should be displayed in the dialog box.
Help please.

You have a try block around the entire workflow. Add another try block around the code in question but leave off the “on error” part.


You could check to see if the file exists before trying to use it.

I figured out yesterday that if you leave the on error block “blank” like so :

-- your code
on error
-- do nothing to skip the error
end try

… well you get no error at all. At least that worked for me last night :slight_smile:

The thing is, I think, you have to make sure you identify the part of the code that gives you an error. You need to to try several combinations… and see what works.

That is because you did not specify anything to happen when the error occurred. If you are not
going to use the error then it is best to leave it out. This way it is clear to you and anyone else
reading your code that you want to skip any error that may come up.

-- your code
end try

Yeah I hear that, but I jsut didn’t know what to do with that error, so I decided to ignore it by using the code I posted.
Let’s face it, it’s the easy way out but for a newbie like me it works out :slight_smile:

I thought about it, I was not sure if a try block within a try block would work. Thanks Craig, I will try it now.