[jdom-interest] NoSuch*Exceptions in JDOM

Jools Enticknap jools at jools.org
Fri Jun 16 07:52:00 PDT 2000


On Fri, 16 Jun 2000, Thomas M. Sasala wrote:

> Dino Valente wrote:
> > 
> > At 04:57 PM 6/15/00 -0500, Brett McLaughlin wrote:
> > >Simon Rade wrote:
> > > >
> > > > Hi!
> > > >
> > > > Element's methods getAttribute() and getChild() now throws
> > > > NoSuchElementException and NoSuchAttributeException.
> > > > Do you think this is better than returning null in such cases?
> > > > Since it often happens that you don't know whether child or attribute
> > > > exists and it is very awkward to handle those Exceptions.
> > >
> > >Yup. We went over this a bit - you don't want to ever have to really
> > >check for null in code, it isn't that great of a practice.
> > 
> > I disagree. Doing a try/catch for each optional attribute or element is
> > even worse.
> > 
> 	I agree.  The exception (in this case) is a real pain.
> we created a util that just returns null.....

Mmmm, I have to admit I ended up doing the same thing.

if NoSuchElementException is designed, simply to eliminate the need to
check for a null, then I would suggest that using a List is just as heavy
weight.

Endulge me;

1) Using get child.

Element e = null;
try {
	e = elem.getChild( "foo" );
} catch( NoSuchElementException e ) ) {
	// Handle the exception
}


2) Using getChildren

List l = elem.getChildren( "foo" );
if ( l.size() > 0 ) {
	// Do your stuff
} else {
	// Do something else.
} 


3) Using getChild if it returned null.

Element e = elem.getChild( "foo" );
if ( e != null ) {
	// Do my stuff.
}
else {
	// Do something else.
}


Of the three I'd go for example (3)  every time. 

It's a dichotomy, for NoSuchElementException to exist in this context
because for an element not to have a child is perfectly reasonable, and
it's not an exceptional condition. IMOHO.



--Jools








Received: from chmls06.mediaone.net (chmls06.mediaone.net [24.147.1.144])
	by dorothy.denveronline.net (8.9.3/8.9.3) with ESMTP id IAA19857
	for <jdom-interest at jdom.org>; Fri, 16 Jun 2000 08:11:36 -0600 (MDT)
Received: from sasha ([24.147.232.47])
	by chmls06.mediaone.net (8.8.7/8.8.7) with SMTP id KAA13833;
	Fri, 16 Jun 2000 10:11:32 -0400 (EDT)
Message-ID: <00f101bfd79c$7807f280$6601a8c0 at sasha>
Reply-To: "Anne Thomas Manes" <anne at manes.net>
From: "Anne Thomas Manes" <annethomas at earthlink.net>
To: "Jon Baer" <jonbaer at digitalanywhere.com>, <jdom-interest at jdom.org>,
        "Simon St.Laurent" <simonstl at simonstl.com>
References: <200005081342.JAA03630 at hesketh.net>
Subject: Re: [jdom-interest] SOAP?
Date: Fri, 16 Jun 2000 07:03:26 -0700
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.00.2919.6700
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700
Sender: jdom-interest-admin at jdom.org
Errors-To: jdom-interest-admin at jdom.org
X-BeenThere: jdom-interest at jdom.org
X-Mailman-Version: 2.0beta2
Precedence: bulk
List-Id: JDOM Mailing List for General Issues and Updates <jdom-interest.jdom.org>

 FYI:

Thought you might be interested in this comparative review of the IBM and
Microsoft SOAP implementations.

http://windows.oreilly.com/news/soapreview_0600.html

By the way, Sun is less unhappy about SOAP than before.

Anne Manes

----- Original Message -----
From: "Simon St.Laurent" <simonstl at simonstl.com>
To: "Jon Baer" <jonbaer at digitalanywhere.com>; <jdom-interest at jdom.org>
Sent: Monday, May 08, 2000 6:44 AM
Subject: Re: [jdom-interest] SOAP?


> At 05:57 AM 5/8/00 +0000, Jon Baer wrote:
> >Ehhh anyone know anything about this:
> >http://msdn.microsoft.com/workshop/xml/general/soapspec.asp
> >
> >Would there then be a need to develop a SOAPBuilder?  Is anyone using
> >this protocol?
>
> Lots of people are using SOAP for various things.  Check out:
> http://www.xmlhack.com/list.php?cat=25
> for news on SOAP and other XML protocols.
>
> Sun seems deeply unhappy with SOAP, while Microsoft seems quite pleased by
> it.  IBM's joined the SOAP side of this issue.  It'll be a long while
> sorting out.
>
> The good news is that SOAP messages are plain old ordinary XML (simple at
> that), and shouldn't need a specific builder - just some logic and a
> connection to HTTP.
>
> Simon St.Laurent
> XML Elements of Style / XML: A Primer, 2nd Ed.
> Building XML Applications
> Inside XML DTDs: Scientific and Technical
> Cookies / Sharing Bandwidth
> http://www.simonstl.com
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
>
>




More information about the jdom-interest mailing list