<html>
<link rel="stylesheet" href="josh.css">
<body bgcolor="#FFFFFF">

		<div id="Description">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">DOMException</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">6</span>  IE <span class="emphasis">n/a</span>  DOM <span class="emphasis">1</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal"></p>
					</td><td valign="top" nowrap class="requirements">&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>Some operations on W3C DOM objects can trigger errors, or, in the
vernacular of JavaScript 1.5, throw exceptions, if something goes
wrong. The W3C DOM defines an object that conveys a code number
corresponding to a well-defined (if limited) list of exceptions. For
example, if you attempt to append one text node as a child of another
text node, the <span class="literal">appendChild( )</span> method of such an
operation throws an exception whose code number is 3. This number
corresponds to the exception that signals an attempt to perform an
illegal or logically impossible action on a DOM hierarchy (a text
node can't have any child nodes).
</p>
							</td>
						</tr>
						<tr>
							<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
						</tr>
						<tr>
							<td colspan="2"><p>			The job of conveying the DOM exception information to a scripter
falls to the hosting environment, rather than the DOM. Because
JavaScript 1.5 already has an exception handling mechanism, the task
of blending the <span class="literal">DOMException</span> system with
JavaScript exception handling fell first to Netscape, as implemented
in Netscape 6. The new mechanism permits different kinds of error
objects to circulate through the exception handling operations, thus
leaving the original system intact, while extending the mechanism to
accommodate not only the W3C DOM <span class="literal">DOMException</span>
object, but some Netscape-specific errors, as well. Processing of
exceptions of all kinds continues to take place in the
<span class="literal">catch</span> block of a
<span class="literal">try</span>/<span class="literal">catch</span> construction, and all
information about the exception is still passed as an object through
a single parameter to the <span class="literal">catch</span> block.
</p>
							</td>
						</tr>
						<tr>
							<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
						</tr>
						<tr>
							<td colspan="2"><p>			Netscape's DOM exception object (which embodies the
W3C <span class="literal">DOMException</span> object) arrives at the
<span class="literal">catch</span> block with a longer list of properties and
methods associated with it than does an exception arising from other
causes (e.g., trying to use a JavaScript variable that has not been
initialized). The distinguishing property of a
<span class="literal">DOMException</span> object, missing from the other types,
is the <span class="literal">code</span> property. Moreover, any code value
between 1 and 15 indicates an exception type known to the formal DOM
specification through Level 2. Others will certainly be added to the
list in the future. Netscape uses code numbers starting with 1000 for
its list of browser-specific exceptions.
</p>
							</td>
						</tr>
						<tr>
							<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
						</tr>
						<tr>
							<td colspan="2"><p>			If you wish to process true W3C DOM exceptions along their own
execution path, you can use a construction similar to the following
(which allows for the <span class="literal">DOMException</span> list to grow to
999 in future iterations):
</p>
<span class="PROGRAMLISTING"><pre>try {
    // your DOM-related statement goes here
}
catch(e) {
    if (typeof e.code == &quot;number&quot;) {
        if (e.code&lt; 1000) {
            // process DOMException object here
        } else {
            // process Netscape DOM exception object here
        }
    } else {
        // process language or other exceptions here
    }
} </pre></span>
							</td>
						</tr>
						<tr>
							<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
						</tr>
						<tr>
							<td colspan="2"><p>			Of course, it is highly unlikely that exception details will be of
benefit to users, but they are invaluable to you during development.
For more on exception handling, see the <span class="literal">error</span>
object in Chapter 12.
</p>
												</td>
</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="objectmodelreference"><span class="title">Object Model Reference</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td><span class="programlisting"><pre><span class="replaceable">errorObjectReference</span></pre>
						</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="objectspecificproperties"><span class="title">Object-Specific Properties</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			<span class="literal">code</span></p>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="objectspecificmethods"><span class="title">Object-Specific Methods</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			None. </p>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="objectspecificeventhandlerproperties"><span class="title">Object-Specific Event Handler Properties</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			None. </p>
					</td>
				</tr>
			</table>
		</div><div id="code">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">code</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">6</span> IE <span class="emphasis">n/a</span>  DOM <span class="emphasis">1</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal"></p>
					</td><td valign="top" nowrap class="requirements">Read-only&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>Provides an integer corresponding to one of the defined DOM error
types. The following table lists all code values, their constant
equivalents, and examples of what kinds of problems throw the
exception.
</p>
							</td>
						</tr>
						<tr>
							<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
						</tr>
						<tr>
							<td>
								<table border="1"><tbody><tr><th>Code</th><th>Constant</th><th>Most likely cause</th></tr>
										<tr><td><span class="literal">1</span></td><td><span class="literal">INDEX_SIZE_ERR</span></td><td>An integer offset parameter is out of the range of the target object</td>
										</tr>
										<tr><td><span class="literal">2</span></td><td><span class="literal">DOMSTRING_SIZE_ERR</span></td><td>Property string value is too large for the hosting language</td>
										</tr>
										<tr><td><span class="literal">3</span></td><td><span class="literal">HIERARCHY_REQUEST_ERR</span></td><td>Appending a child to a node not capable of children</td>
										</tr>
										<tr><td><span class="literal">4</span></td><td><span class="literal">WRONG_DOCUMENT_ERR</span></td><td>Inserting a node created from a different document (without passing
through the import process)
</td>
										</tr>
										<tr><td><span class="literal">5</span></td><td><span class="literal">INVALID_CHARACTER_ERR</span></td><td>Assigning an identifier with an illegal character</td>
										</tr>
										<tr><td><span class="literal">6</span></td><td><span class="literal">NO_DATA_ALLOWED_ERR</span></td><td>Assigning data to a node that doesn't allow data</td>
										</tr>
										<tr><td><span class="literal">7</span></td><td><span class="literal">NO_MODIFICATION_ALLOWED_ERR</span></td><td>Assigning a value to a read-only property</td>
										</tr>
										<tr><td><span class="literal">8</span></td><td><span class="literal">NOT_FOUND_ERR</span></td><td>Method parameter reference to a nonexistent node in the
object's scope
</td>
										</tr>
										<tr><td><span class="literal">9</span></td><td><span class="literal">NOT_SUPPORTED_ERR</span></td><td>Invoking an XML-only method in an HTML document</td>
										</tr>
										<tr><td><span class="literal">10</span></td><td><span class="literal">INUSE_ATTRIBUTE_ERR</span></td><td>Method parameter to an <span class="literal">Attr</span> node that already
belongs to another element (without cloning the
<span class="literal">Attr</span> first)
</td>
										</tr>
										<tr><td><span class="literal">11</span></td><td><span class="literal">INVALID_STATE_ERR</span></td><td>Referencing a node that is not readable or writable</td>
										</tr>
										<tr><td><span class="literal">12</span></td><td><span class="literal">SYNTAX_ERR</span></td><td>A slippery keyboard</td>
										</tr>
										<tr><td><span class="literal">13</span></td><td><span class="literal">INVALID_MODIFICATION_ERR</span></td><td>Modifying the type of a node</td>
										</tr>
										<tr><td><span class="literal">14</span></td><td><span class="literal">NAMESPACE_ERR</span></td><td>Namespace mismatch or malformed name</td>
										</tr>
										<tr><td><span class="literal">15</span></td><td><span class="literal">INVALID_ACCESS_ERR</span></td><td>You can't go there</td>
										</tr>
									</tbody></table>
												</td>
</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="example"><span class="title">Example</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td><span class="programlisting"><pre>if (e.code == e.INVALID_CHARACTER_ERR) {
    // process for an illegal identifier character
}</pre>
						</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="value"><span class="title">Value</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			Integer</p>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap colspan="2" class="default"><span class="title">Default</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			Determined by error.</p>
					</td>
				</tr>
			</table>
		</div>

</body>
</html>