
Photoshop 7.0 Scripting Guide
31
Scripting basics
Testing and troubleshooting
2
2.10.4 Error handling
The following examples show how to stop a script from executing when a specific file cannot
be found.
AS
--Store a reference to the document with the name "My Document"
--If it does not exist, display an error message
tell application "Adobe Photoshop 7.0"
try
set docRef to document "My Document"
display dialog "Found 'My Document' "
on error
display dialog "Couldn't locate document 'My Document'"
end try
end tell
VB
Private Sub Command1_Click()
' Store a reference to the document with the name "My Document"
' If the document does not exist, display an error message.
Dim appRef As New Photoshop.Application
Dim docRef As Photoshop.Document
Dim errorMessage As String
Dim docName As String
docName = "My Document"
Set docRef = appRef.ActiveDocument
On Error GoTo DisplayError
Set docRef = appRef.Documents(docName)
MsgBox "Document Found!"
Exit Sub
DisplayError:
errorMessage = "Couldn't locate document " & "'" & docName & "'"
MsgBox errorMessage
End Sub