[jdom-interest] NoSuch*Exceptions: the definitive example(s) - part 2

Patrick Dowler Patrick.Dowler at nrc.ca
Mon Jul 10 10:29:46 PDT 2000


In the main example message, I showed the typical usage:

try
{
     Element e =my.getChild("well").getChild("hidden").getChild("leaf");
     // do something with the "leaf"
} 
catch (NoSuchChildException ncex) 
{
     // which element was missing?

}

which is certainly concise. However, if we have/had XPath, wouldn't
you be doing this with something like:

try
{
    Path p = new Path();
    p.add("well");
    p.add("hidden");
    p.add("leaf");
    Element e = my.getChild(p);
}
catch (NoSuchPathException npex) 
{
     Element e = npex.getLastExistingElement();
     // handle missing child of e
}

I don't know anything about XPath, but if it supports a realtive path in
the data structure, then it would be a way to do those multiple-child
lookups (which are paths).... ???

-- 

Patrick Dowler
Canadian Astronomy Data Centre




More information about the jdom-interest mailing list