Call method and try on error

Hi,

I would like to know how to trap error if for any reason the call method go in error.
Example suppose that file don’t exist
Error say that pListDict is not defined but the try don’t intercept the error.

Second question is: Call method works on Yosemite in ASS app generated on 10.6.8?

set pListPath to “/Users/hagi/Desktop/com.mycompany.plist”
try
set pListDict to call method “dictionaryWithContentsOfFile:” of class “NSDictionary” with parameter pListPath
on error msg number errnum
log msg
end try

Ame

Maybe an obvious solution, but why wouldn’t you check if the file exists yourself?

To answer you question. You can easily check if the plistdict is defined. A command in AppleScript can return nothing if it wants to, that doesn’t mean it contains an error. You need to check the contents of the variable:

set pListPath to "/Users/hagi/Desktop/com.mycompany.plist"
set pListDict to call method "dictionaryWithContentsOfFile:" of class "NSDictionary" with parameter pListPath
try
pListDict
on error msg number errnum
log msg
end try