throw new DomEx(DomEx.WRONG_DOCUMENT_ERR,
throw new DomDOMException(DOMException.WRONG_DOCUMENT_ERR,
  public Node replaceChild(Node newChild, Node refChild)  {    try      {        DomNode child = (DomNode) newChild;        DomNode ref = (DomNode) refChild;                DomEvent.DomMutationEvent event = getMutationEvent();        boolean doFree = (event != null);                    if (child.nodeType == DOCUMENT_FRAGMENT_NODE)          {            // Append all nodes in the fragment to this node            for (DomNode ctx = child.first; ctx != null; ctx = ctx.next)              {                checkMisc(ctx);              }            if (ref == null || ref.parent != this)              {                throw new DomEx(DomEx.NOT_FOUND_ERR, null, ref, 0);              }                        if (reportMutations)              {                removalEvent(event, ref);              }            length--;            length += child.length;                        if (child.length == 0)              {                // Removal                if (ref.previous != null)                  {                    ref.previous.next = ref.next;                  }                if (ref.next != null)                  {                    ref.next.previous = ref.previous;                  }                if (first == ref)                  {                    first = ref.next;                  }                if (last == ref)                  {                    last = ref.previous;                  }              }            else              {                int i = ref.index;                for (DomNode ctx = child.first; ctx != null; ctx = ctx.next)                  {                    // Insertion                    ctx.parent = this;                    ctx.index = i++;                    ctx.setDepth(ref.depth);                    if (ctx == child.first)                      {                        ctx.previous = ref.previous;                      }                    if (ctx == child.last)                      {                        ctx.next = ref.next;                      }                  }                if (first == ref)                  {                    first = child.first;                  }                if (last == ref)                  {                    last = child.last;                  }              }          }        else          {            checkMisc(child);            if (ref == null || ref.parent != this)              {                throw new DomEx(DomEx.NOT_FOUND_ERR, null, ref, 0);              }                    if (reportMutations)              {                removalEvent(event, ref);              }                        if (child.parent != null)              {                child.parent.removeChild(child);              }            child.parent = this;            child.index = ref.index;            child.setDepth(ref.depth);            if (ref.previous != null)              {                ref.previous.next = child;              }            child.previous = ref.previous;            if (ref.next != null)              {                ref.next.previous = child;              }            child.next = ref.next;            if (first == ref)              {                first = child;              }            if (last == ref)              {                last = child;              }            if (reportMutations)              {                insertionEvent(event, child);              }            if (doFree)              {                freeMutationEvent();              }          }        ref.parent = null;        ref.index = 0;        ref.setDepth(0);        ref.previous = null;        ref.next = null;                return ref;      }    catch (ClassCastException e)      {        throw new DomEx(DomEx.WRONG_DOCUMENT_ERR,                        null, newChild, 0);      }  }