🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #8449

Re: JavaScript Error Handling Question

#8449
From: Dave_Saunders
Date: Sat, 14 Oct 2006 00:36
26 lines
1886 bytes
Jim,

I just tried your function and it did catch the error, so I'm not quite sure what to say.

The essence of the situation is this. When you use any of the item() methods to access members of a collection, what you get is called an object specifier. It, in effect, describes the request you just made, it doesn't satisfy it. It is, if you like, a pointer into the object model.

If the object does not exist at this moment, you do not get an error. Instead, the object specifier evaluates to null. So, to check if the object (or objects) exists (or exist), check to see if the variable is null.

theAttr = theRootEle.xmlAttributes.item("test");
if (theAttr != null) {
// we have an attribute
}

The other way to do it is what you did:

try {
theAttrValue = theAttr.value
} catch (e) {
// theAttr does not exist
}

A corollary to all this is that even those theAttr is null when you first create the specifier, if you bring the object in question into existence before trying to use it, then when you do use it, it will be there.

It can be very confusing. The getElements() call can help you because it will convert an object specifier into an array of resolved object references (although you don't need this for what you're doing).

Dave
Technical Details
Message-ID: <3bc1f75d.0@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!news2.volia.net!news.ecp.fr!news.stben.net!webcrossing
References: <3bc1f75d.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,3b05154e3909ab65,start
X-Google-Attributes: gidf939a,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Dave_Saunders@adobeforums.com
Newsgroups: adobe.scripting.indesign
Subject: Re: JavaScript Error Handling Question
Message-ID: <3bc1f75d.0@webcrossing.la2eafNXanI>
Date: Fri, 13 Oct 2006 17:36:28 -0700
References: <3bc1f75d.-1@webcrossing.la2eafNXanI>
Lines: 36
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!news2.volia.net!news.ecp.fr!news.stben.net!webcrossing