[jdom-interest] [Vote] NoSuchChildException

Elliotte Rusty Harold elharo at metalab.unc.edu
Thu Jul 13 10:49:19 PDT 2000

At 3:00 AM -0700 7/13/00, Alex Chaffee wrote:

>Not true.
>NoSuchElementException is only thrown by one class, Enumeration, which
>belongs to the JDK 1.0 flawed collections API.  The JDK 1.2
>collections (which, IMHO, should have been named java.util.collections
>or javax.collections to avoid namespace and brainspace collisions with
>Vector and friends) are very consistent in returning null from get()

Yes it is true. NoSuchElementException is thrown by the next() method 
of the Iterator interface, as well as by the nextElement() method of 
the Enumeration interface. For example from ListIterator:

public Object next()

       Returns the next element in the list. This method may be
       called repeatedly to iterate through the list, or intermixed
       with calls to previous to go back and forth. (Note that
       alternating calls to next and previous will return the same
       element repeatedly.)
       Specified by:
             next in interface Iterator
             the next element in the list.
             NoSuchElementException - if the iteration has no next

It's thrown in other places too. For example, here's a bit of source 
code for one of the get methods in LinkedList.java in JDK 1.3:

      * Returns the last element in this list.
      * @return the last element in this list.
      * @throws    NoSuchElementException if this list is empty.
     public Object getLast()  {
	if (size==0)
	    throw new NoSuchElementException();

	return header.previous.element;

NoSuchElementException is not deprecated. It is used and thrown in 
the Java Colelctions API.

| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
|                  The XML Bible (IDG Books, 1999)                   |
|              http://metalab.unc.edu/xml/books/bible/               |
|   http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/   |
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ |
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |

More information about the jdom-interest mailing list