[jdom-interest] TODO clone [eg]

Joseph Bowbeer jozart at csi.com
Tue Apr 17 11:26:10 PDT 2001

Joe Bowbeer writes:

> > In which case it's time for plan B:
> >
> > If we don't add the exception to the declaration, we
> > should at least throw an InternalError as a sanity check
> > in our own implementations:
> >
> >     public Object clone() {
> >         try {
> >             return super.clone();
> >         }
> >         catch (CloneNotSupportedException ex) {
> >             throw new InternalError();
> >         }
> >     }
> >

Ken Rune Helland writes:

> Since Element, Document and so on all implement the Clonable
> interface super.clone(), wich is in effect Object.clone() since
> all these classes are direct subclasses of Object, will never
> throw CloneNotSuppotedException, so the catch clause can
> safely be left empty.

Realize that Plan B applies only to our clone implementation inside Element,
etc., not to user code.

My suggestion is based on the principle that exceptions should never be
ignored.  Throwing an Error makes the code more portable and robust.

By the way, it's possible for Object.clone() to appear to throw a

For example, try this:


Or there really could be an internal error... In any case, failing fast is
slightly better than doing nothing.

Joe Bowbeer

More information about the jdom-interest mailing list