[jdom-interest] NoSuch*Exceptions in JDOM

Petri Wessman orava at termiitti.akumiitti.fi
Mon Jul 10 00:46:53 PDT 2000


On Sun, 09 Jul 2000 12:55:49 -0700, Jason Hunter <jhunter at acm.org> said:

>> Unfortunately, Messrs. McLaughlin and Hunter seem to prefer a frenzy of
>> exceptions.

Jason> I'm still flexible.  But let me say, I'm not swayed by the
Jason> "ivory tower" question of "is this exceptional or not" but
Jason> rather I'm swayed by use cases that make one approach more
Jason> appealing than the other.  Unfortunately, selecting either
Jason> approach currently involves making certain use cases overly
Jason> complicated.  So, other things being equal, I'm currently
Jason> supporting throwing exceptions because I just know returning
Jason> null means there'll be a lot of damn NullPointerException
Jason> errors, without any decent description of what went wrong.
Jason> Sirtaj Singh Kang made some very compelling arguments along
Jason> these lines.

I can understand your viewpoint (even if I don't completely agree with
it :). However, the accessor methods throwing exceptions is a major
hassle for me, and causes some code slowdown (exception handling is
*slow* compared to other things in Java). Having optional attributes in
XML is more of a rule than an exception...

How about making another accessor method for elements and attributes
that returns null? Some of us *do* need that, and having a separate
method for that would still keep the "main" access methods
beginner-friendly.

Or maybe something like this:

  String getAttribute (String key, String defaultVal);

which would return the default value if the attribute was missing?
That would enable us to set the default to null (or whatever) and skip
the exceptions.

//Petri



More information about the jdom-interest mailing list