
Photoshop CS Scripting Guide
29
Scripting basics
Debugging and Error Handling
2
2.10.3 JavaScript Debugging
JavaScript debugging is described in detail in the JavaScript Reference Guide on the
Photoshop installation CD. Please refer to that document for further information.
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 CS"
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