Thursday, January 19, 2017

#1 2014-11-11 03:08:00 pm

ame
Member
Registered: 2011-06-28
Posts: 151

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


Filed under: plist, Yosemite, call method

Offline

 

#2 2014-11-12 06:05:14 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2550

Re: Call method and try on error

ame wrote:

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.

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:


Applescript:

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

Online

 

Board footer

Powered by FluxBB

[ Generated in 0.064 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)