| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="prev" href="dom-pi-objects.html" /> |
| 13 | <link rel="parent" href="node652.html" /> |
| 14 | <link rel="next" href="dom-conformance.html" /> |
| 15 | <meta name='aesop' content='information' /> |
| 16 | <title>13.6.2.12 Exceptions </title> |
| 17 | </head> |
| 18 | <body> |
| 19 | <DIV CLASS="navigation"> |
| 20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 22 | <tr> |
| 23 | <td class='online-navigation'><a rel="prev" title="13.6.2.11 ProcessingInstruction Objects" |
| 24 | href="dom-pi-objects.html"><img src='../icons/previous.png' |
| 25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 26 | <td class='online-navigation'><a rel="parent" title="13.6.2 Objects in the" |
| 27 | href="node652.html"><img src='../icons/up.png' |
| 28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 29 | <td class='online-navigation'><a rel="next" title="13.6.3 Conformance" |
| 30 | href="dom-conformance.html"><img src='../icons/next.png' |
| 31 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 32 | <td align="center" width="100%">Python Library Reference</td> |
| 33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 34 | href="contents.html"><img src='../icons/contents.png' |
| 35 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 36 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 37 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 38 | <td class='online-navigation'><a rel="index" title="Index" |
| 39 | href="genindex.html"><img src='../icons/index.png' |
| 40 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 41 | </tr></table> |
| 42 | <div class='online-navigation'> |
| 43 | <b class="navlabel">Previous:</b> |
| 44 | <a class="sectref" rel="prev" href="dom-pi-objects.html">13.6.2.11 ProcessingInstruction Objects</A> |
| 45 | <b class="navlabel">Up:</b> |
| 46 | <a class="sectref" rel="parent" href="node652.html">13.6.2 Objects in the</A> |
| 47 | <b class="navlabel">Next:</b> |
| 48 | <a class="sectref" rel="next" href="dom-conformance.html">13.6.3 Conformance</A> |
| 49 | </div> |
| 50 | <hr /></div> |
| 51 | </DIV> |
| 52 | <!--End of Navigation Panel--> |
| 53 | |
| 54 | <H3><A NAME="SECTION00156212000000000000000"></A><A NAME="dom-exceptions"></A> |
| 55 | <BR> |
| 56 | 13.6.2.12 Exceptions |
| 57 | </H3> |
| 58 | |
| 59 | <P> |
| 60 | |
| 61 | <span class="versionnote">New in version 2.1.</span> |
| 62 | |
| 63 | <P> |
| 64 | The DOM Level 2 recommendation defines a single exception, |
| 65 | <tt class="exception">DOMException</tt>, and a number of constants that allow |
| 66 | applications to determine what sort of error occurred. |
| 67 | <tt class="exception">DOMException</tt> instances carry a <tt class="member">code</tt> attribute |
| 68 | that provides the appropriate value for the specific exception. |
| 69 | |
| 70 | <P> |
| 71 | The Python DOM interface provides the constants, but also expands the |
| 72 | set of exceptions so that a specific exception exists for each of the |
| 73 | exception codes defined by the DOM. The implementations must raise |
| 74 | the appropriate specific exception, each of which carries the |
| 75 | appropriate value for the <tt class="member">code</tt> attribute. |
| 76 | |
| 77 | <P> |
| 78 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4428' xml:id='l2h-4428' class="exception">DOMException</tt></b></dt> |
| 79 | <dd> |
| 80 | Base exception class used for all specific DOM exceptions. This |
| 81 | exception class cannot be directly instantiated. |
| 82 | </dd></dl> |
| 83 | |
| 84 | <P> |
| 85 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4429' xml:id='l2h-4429' class="exception">DomstringSizeErr</tt></b></dt> |
| 86 | <dd> |
| 87 | Raised when a specified range of text does not fit into a string. |
| 88 | This is not known to be used in the Python DOM implementations, but |
| 89 | may be received from DOM implementations not written in Python. |
| 90 | </dd></dl> |
| 91 | |
| 92 | <P> |
| 93 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4430' xml:id='l2h-4430' class="exception">HierarchyRequestErr</tt></b></dt> |
| 94 | <dd> |
| 95 | Raised when an attempt is made to insert a node where the node type |
| 96 | is not allowed. |
| 97 | </dd></dl> |
| 98 | |
| 99 | <P> |
| 100 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4431' xml:id='l2h-4431' class="exception">IndexSizeErr</tt></b></dt> |
| 101 | <dd> |
| 102 | Raised when an index or size parameter to a method is negative or |
| 103 | exceeds the allowed values. |
| 104 | </dd></dl> |
| 105 | |
| 106 | <P> |
| 107 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4432' xml:id='l2h-4432' class="exception">InuseAttributeErr</tt></b></dt> |
| 108 | <dd> |
| 109 | Raised when an attempt is made to insert an <tt class="class">Attr</tt> node that |
| 110 | is already present elsewhere in the document. |
| 111 | </dd></dl> |
| 112 | |
| 113 | <P> |
| 114 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4433' xml:id='l2h-4433' class="exception">InvalidAccessErr</tt></b></dt> |
| 115 | <dd> |
| 116 | Raised if a parameter or an operation is not supported on the |
| 117 | underlying object. |
| 118 | </dd></dl> |
| 119 | |
| 120 | <P> |
| 121 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4434' xml:id='l2h-4434' class="exception">InvalidCharacterErr</tt></b></dt> |
| 122 | <dd> |
| 123 | This exception is raised when a string parameter contains a |
| 124 | character that is not permitted in the context it's being used in by |
| 125 | the XML 1.0 recommendation. For example, attempting to create an |
| 126 | <tt class="class">Element</tt> node with a space in the element type name will |
| 127 | cause this error to be raised. |
| 128 | </dd></dl> |
| 129 | |
| 130 | <P> |
| 131 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4435' xml:id='l2h-4435' class="exception">InvalidModificationErr</tt></b></dt> |
| 132 | <dd> |
| 133 | Raised when an attempt is made to modify the type of a node. |
| 134 | </dd></dl> |
| 135 | |
| 136 | <P> |
| 137 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4436' xml:id='l2h-4436' class="exception">InvalidStateErr</tt></b></dt> |
| 138 | <dd> |
| 139 | Raised when an attempt is made to use an object that is not defined or is no |
| 140 | longer usable. |
| 141 | </dd></dl> |
| 142 | |
| 143 | <P> |
| 144 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4437' xml:id='l2h-4437' class="exception">NamespaceErr</tt></b></dt> |
| 145 | <dd> |
| 146 | If an attempt is made to change any object in a way that is not |
| 147 | permitted with regard to the |
| 148 | <em class="citetitle"><a |
| 149 | href="http://www.w3.org/TR/REC-xml-names/" |
| 150 | title="Namespaces in XML" |
| 151 | >Namespaces in XML</a></em> |
| 152 | recommendation, this exception is raised. |
| 153 | </dd></dl> |
| 154 | |
| 155 | <P> |
| 156 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4438' xml:id='l2h-4438' class="exception">NotFoundErr</tt></b></dt> |
| 157 | <dd> |
| 158 | Exception when a node does not exist in the referenced context. For |
| 159 | example, <tt class="method">NamedNodeMap.removeNamedItem()</tt> will raise this if |
| 160 | the node passed in does not exist in the map. |
| 161 | </dd></dl> |
| 162 | |
| 163 | <P> |
| 164 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4439' xml:id='l2h-4439' class="exception">NotSupportedErr</tt></b></dt> |
| 165 | <dd> |
| 166 | Raised when the implementation does not support the requested type |
| 167 | of object or operation. |
| 168 | </dd></dl> |
| 169 | |
| 170 | <P> |
| 171 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4440' xml:id='l2h-4440' class="exception">NoDataAllowedErr</tt></b></dt> |
| 172 | <dd> |
| 173 | This is raised if data is specified for a node which does not |
| 174 | support data. |
| 175 | </dd></dl> |
| 176 | |
| 177 | <P> |
| 178 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4441' xml:id='l2h-4441' class="exception">NoModificationAllowedErr</tt></b></dt> |
| 179 | <dd> |
| 180 | Raised on attempts to modify an object where modifications are not |
| 181 | allowed (such as for read-only nodes). |
| 182 | </dd></dl> |
| 183 | |
| 184 | <P> |
| 185 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4442' xml:id='l2h-4442' class="exception">SyntaxErr</tt></b></dt> |
| 186 | <dd> |
| 187 | Raised when an invalid or illegal string is specified. |
| 188 | </dd></dl> |
| 189 | |
| 190 | <P> |
| 191 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-4443' xml:id='l2h-4443' class="exception">WrongDocumentErr</tt></b></dt> |
| 192 | <dd> |
| 193 | Raised when a node is inserted in a different document than it |
| 194 | currently belongs to, and the implementation does not support |
| 195 | migrating the node from one document to the other. |
| 196 | </dd></dl> |
| 197 | |
| 198 | <P> |
| 199 | The exception codes defined in the DOM recommendation map to the |
| 200 | exceptions described above according to this table: |
| 201 | |
| 202 | <P> |
| 203 | <div class="center"><table class="realtable"> |
| 204 | <thead> |
| 205 | <tr> |
| 206 | <th class="left" >Constant</th> |
| 207 | <th class="left" >Exception</th> |
| 208 | </tr> |
| 209 | </thead> |
| 210 | <tbody> |
| 211 | <tr><td class="left" valign="baseline"><tt class="constant">DOMSTRING_SIZE_ERR</tt></td> |
| 212 | <td class="left" ><tt class="exception">DomstringSizeErr</tt></td></tr> |
| 213 | <tr><td class="left" valign="baseline"><tt class="constant">HIERARCHY_REQUEST_ERR</tt></td> |
| 214 | <td class="left" ><tt class="exception">HierarchyRequestErr</tt></td></tr> |
| 215 | <tr><td class="left" valign="baseline"><tt class="constant">INDEX_SIZE_ERR</tt></td> |
| 216 | <td class="left" ><tt class="exception">IndexSizeErr</tt></td></tr> |
| 217 | <tr><td class="left" valign="baseline"><tt class="constant">INUSE_ATTRIBUTE_ERR</tt></td> |
| 218 | <td class="left" ><tt class="exception">InuseAttributeErr</tt></td></tr> |
| 219 | <tr><td class="left" valign="baseline"><tt class="constant">INVALID_ACCESS_ERR</tt></td> |
| 220 | <td class="left" ><tt class="exception">InvalidAccessErr</tt></td></tr> |
| 221 | <tr><td class="left" valign="baseline"><tt class="constant">INVALID_CHARACTER_ERR</tt></td> |
| 222 | <td class="left" ><tt class="exception">InvalidCharacterErr</tt></td></tr> |
| 223 | <tr><td class="left" valign="baseline"><tt class="constant">INVALID_MODIFICATION_ERR</tt></td> |
| 224 | <td class="left" ><tt class="exception">InvalidModificationErr</tt></td></tr> |
| 225 | <tr><td class="left" valign="baseline"><tt class="constant">INVALID_STATE_ERR</tt></td> |
| 226 | <td class="left" ><tt class="exception">InvalidStateErr</tt></td></tr> |
| 227 | <tr><td class="left" valign="baseline"><tt class="constant">NAMESPACE_ERR</tt></td> |
| 228 | <td class="left" ><tt class="exception">NamespaceErr</tt></td></tr> |
| 229 | <tr><td class="left" valign="baseline"><tt class="constant">NOT_FOUND_ERR</tt></td> |
| 230 | <td class="left" ><tt class="exception">NotFoundErr</tt></td></tr> |
| 231 | <tr><td class="left" valign="baseline"><tt class="constant">NOT_SUPPORTED_ERR</tt></td> |
| 232 | <td class="left" ><tt class="exception">NotSupportedErr</tt></td></tr> |
| 233 | <tr><td class="left" valign="baseline"><tt class="constant">NO_DATA_ALLOWED_ERR</tt></td> |
| 234 | <td class="left" ><tt class="exception">NoDataAllowedErr</tt></td></tr> |
| 235 | <tr><td class="left" valign="baseline"><tt class="constant">NO_MODIFICATION_ALLOWED_ERR</tt></td> |
| 236 | <td class="left" ><tt class="exception">NoModificationAllowedErr</tt></td></tr> |
| 237 | <tr><td class="left" valign="baseline"><tt class="constant">SYNTAX_ERR</tt></td> |
| 238 | <td class="left" ><tt class="exception">SyntaxErr</tt></td></tr> |
| 239 | <tr><td class="left" valign="baseline"><tt class="constant">WRONG_DOCUMENT_ERR</tt></td> |
| 240 | <td class="left" ><tt class="exception">WrongDocumentErr</tt></td></tr></tbody> |
| 241 | </table></div> |
| 242 | |
| 243 | <P> |
| 244 | |
| 245 | <DIV CLASS="navigation"> |
| 246 | <div class='online-navigation'> |
| 247 | <p></p><hr /> |
| 248 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 249 | <tr> |
| 250 | <td class='online-navigation'><a rel="prev" title="13.6.2.11 ProcessingInstruction Objects" |
| 251 | href="dom-pi-objects.html"><img src='../icons/previous.png' |
| 252 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 253 | <td class='online-navigation'><a rel="parent" title="13.6.2 Objects in the" |
| 254 | href="node652.html"><img src='../icons/up.png' |
| 255 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 256 | <td class='online-navigation'><a rel="next" title="13.6.3 Conformance" |
| 257 | href="dom-conformance.html"><img src='../icons/next.png' |
| 258 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 259 | <td align="center" width="100%">Python Library Reference</td> |
| 260 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 261 | href="contents.html"><img src='../icons/contents.png' |
| 262 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 263 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 264 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 265 | <td class='online-navigation'><a rel="index" title="Index" |
| 266 | href="genindex.html"><img src='../icons/index.png' |
| 267 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 268 | </tr></table> |
| 269 | <div class='online-navigation'> |
| 270 | <b class="navlabel">Previous:</b> |
| 271 | <a class="sectref" rel="prev" href="dom-pi-objects.html">13.6.2.11 ProcessingInstruction Objects</A> |
| 272 | <b class="navlabel">Up:</b> |
| 273 | <a class="sectref" rel="parent" href="node652.html">13.6.2 Objects in the</A> |
| 274 | <b class="navlabel">Next:</b> |
| 275 | <a class="sectref" rel="next" href="dom-conformance.html">13.6.3 Conformance</A> |
| 276 | </div> |
| 277 | </div> |
| 278 | <hr /> |
| 279 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 280 | </DIV> |
| 281 | <!--End of Navigation Panel--> |
| 282 | <ADDRESS> |
| 283 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 284 | </ADDRESS> |
| 285 | </BODY> |
| 286 | </HTML> |