Commit | Line | Data |
---|---|---|
920dae64 AT |
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="next" href="node35.html" /> | |
13 | <link rel="prev" href="types.html" /> | |
14 | <link rel="parent" href="builtin.html" /> | |
15 | <link rel="next" href="node35.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>2.4 Built-in Exceptions</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="2.3.11 Special Attributes" | |
25 | href="specialattrs.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="2. Built-In Objects" | |
28 | href="builtin.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="2.5 Built-in Constants" | |
31 | href="node35.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="specialattrs.html">2.3.11 Special Attributes</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="builtin.html">2. Built-In Objects</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="node35.html">2.5 Built-in Constants</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION004400000000000000000"> | |
56 | 2.4 Built-in Exceptions</A> | |
57 | </H1> | |
58 | ||
59 | <P> | |
60 | <A NAME="module-exceptions"></A> | |
61 | ||
62 | <P> | |
63 | Exceptions should be class objects. | |
64 | The exceptions are defined in the module <tt class="module">exceptions</tt>. This | |
65 | module never needs to be imported explicitly: the exceptions are | |
66 | provided in the built-in namespace as well as the <tt class="module">exceptions</tt> | |
67 | module. | |
68 | ||
69 | <P> | |
70 | <div class="note"><b class="label">Note:</b> | |
71 | In past versions of Python string exceptions were supported. In | |
72 | Python 1.5 and newer versions, all standard exceptions have been | |
73 | converted to class objects and users are encouraged to do the same. | |
74 | String exceptions will raise a <code>PendingDeprecationWarning</code>. | |
75 | In future versions, support for string exceptions will be removed. | |
76 | ||
77 | <P> | |
78 | Two distinct string objects with the same value are considered different | |
79 | exceptions. This is done to force programmers to use exception names | |
80 | rather than their string value when specifying exception handlers. | |
81 | The string value of all built-in exceptions is their name, but this is | |
82 | not a requirement for user-defined exceptions or exceptions defined by | |
83 | library modules. | |
84 | </div> | |
85 | ||
86 | <P> | |
87 | For class exceptions, in a <tt class="keyword">try</tt><a id='l2h-278' xml:id='l2h-278'></a> statement with | |
88 | an <tt class="keyword">except</tt><a id='l2h-279' xml:id='l2h-279'></a> clause that mentions a particular | |
89 | class, that clause also handles any exception classes derived from | |
90 | that class (but not exception classes from which <em>it</em> is | |
91 | derived). Two exception classes that are not related via subclassing | |
92 | are never equivalent, even if they have the same name. | |
93 | ||
94 | <P> | |
95 | The built-in exceptions listed below can be generated by the | |
96 | interpreter or built-in functions. Except where mentioned, they have | |
97 | an ``associated value'' indicating the detailed cause of the error. | |
98 | This may be a string or a tuple containing several items of | |
99 | information (e.g., an error code and a string explaining the code). | |
100 | The associated value is the second argument to the | |
101 | <tt class="keyword">raise</tt><a id='l2h-280' xml:id='l2h-280'></a> statement. For string exceptions, the | |
102 | associated value itself will be stored in the variable named as the | |
103 | second argument of the <tt class="keyword">except</tt> clause (if any). For class | |
104 | exceptions, that variable receives the exception instance. If the | |
105 | exception class is derived from the standard root class | |
106 | <tt class="exception">Exception</tt>, the associated value is present as the | |
107 | exception instance's <tt class="member">args</tt> attribute, and possibly on other | |
108 | attributes as well. | |
109 | ||
110 | <P> | |
111 | User code can raise built-in exceptions. This can be used to test an | |
112 | exception handler or to report an error condition ``just like'' the | |
113 | situation in which the interpreter raises the same exception; but | |
114 | beware that there is nothing to prevent user code from raising an | |
115 | inappropriate error. | |
116 | ||
117 | <P> | |
118 | The built-in exception classes can be sub-classed to define new | |
119 | exceptions; programmers are encouraged to at least derive new | |
120 | exceptions from the <tt class="exception">Exception</tt> base class. More | |
121 | information on defining exceptions is available in the | |
122 | <em class="citetitle"><a | |
123 | href="../tut/tut.html" | |
124 | title="Python Tutorial" | |
125 | >Python Tutorial</a></em> under the heading | |
126 | ``User-defined Exceptions.'' | |
127 | ||
128 | <P> | |
129 | ||
130 | <P> | |
131 | The following exceptions are only used as base classes for other | |
132 | exceptions. | |
133 | ||
134 | <P> | |
135 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-281' xml:id='l2h-281' class="exception">Exception</tt></b></dt> | |
136 | <dd> | |
137 | The root class for exceptions. All built-in exceptions are derived | |
138 | from this class. All user-defined exceptions should also be derived | |
139 | from this class, but this is not (yet) enforced. The <tt class="function">str()</tt> | |
140 | function, when applied to an instance of this class (or most derived | |
141 | classes) returns the string value of the argument or arguments, or an | |
142 | empty string if no arguments were given to the constructor. When used | |
143 | as a sequence, this accesses the arguments given to the constructor | |
144 | (handy for backward compatibility with old code). The arguments are | |
145 | also available on the instance's <tt class="member">args</tt> attribute, as a tuple. | |
146 | </dd></dl> | |
147 | ||
148 | <P> | |
149 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-282' xml:id='l2h-282' class="exception">StandardError</tt></b></dt> | |
150 | <dd> | |
151 | The base class for all built-in exceptions except | |
152 | <tt class="exception">StopIteration</tt> and <tt class="exception">SystemExit</tt>. | |
153 | <tt class="exception">StandardError</tt> itself is derived from the root class | |
154 | <tt class="exception">Exception</tt>. | |
155 | </dd></dl> | |
156 | ||
157 | <P> | |
158 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-283' xml:id='l2h-283' class="exception">ArithmeticError</tt></b></dt> | |
159 | <dd> | |
160 | The base class for those built-in exceptions that are raised for | |
161 | various arithmetic errors: <tt class="exception">OverflowError</tt>, | |
162 | <tt class="exception">ZeroDivisionError</tt>, <tt class="exception">FloatingPointError</tt>. | |
163 | </dd></dl> | |
164 | ||
165 | <P> | |
166 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-284' xml:id='l2h-284' class="exception">LookupError</tt></b></dt> | |
167 | <dd> | |
168 | The base class for the exceptions that are raised when a key or | |
169 | index used on a mapping or sequence is invalid: <tt class="exception">IndexError</tt>, | |
170 | <tt class="exception">KeyError</tt>. This can be raised directly by | |
171 | <tt class="function">sys.setdefaultencoding()</tt>. | |
172 | </dd></dl> | |
173 | ||
174 | <P> | |
175 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-285' xml:id='l2h-285' class="exception">EnvironmentError</tt></b></dt> | |
176 | <dd> | |
177 | The base class for exceptions that | |
178 | can occur outside the Python system: <tt class="exception">IOError</tt>, | |
179 | <tt class="exception">OSError</tt>. When exceptions of this type are created with a | |
180 | 2-tuple, the first item is available on the instance's <tt class="member">errno</tt> | |
181 | attribute (it is assumed to be an error number), and the second item | |
182 | is available on the <tt class="member">strerror</tt> attribute (it is usually the | |
183 | associated error message). The tuple itself is also available on the | |
184 | <tt class="member">args</tt> attribute. | |
185 | ||
186 | <span class="versionnote">New in version 1.5.2.</span> | |
187 | ||
188 | <P> | |
189 | When an <tt class="exception">EnvironmentError</tt> exception is instantiated with a | |
190 | 3-tuple, the first two items are available as above, while the third | |
191 | item is available on the <tt class="member">filename</tt> attribute. However, for | |
192 | backwards compatibility, the <tt class="member">args</tt> attribute contains only a | |
193 | 2-tuple of the first two constructor arguments. | |
194 | ||
195 | <P> | |
196 | The <tt class="member">filename</tt> attribute is <code>None</code> when this exception is | |
197 | created with other than 3 arguments. The <tt class="member">errno</tt> and | |
198 | <tt class="member">strerror</tt> attributes are also <code>None</code> when the instance was | |
199 | created with other than 2 or 3 arguments. In this last case, | |
200 | <tt class="member">args</tt> contains the verbatim constructor arguments as a tuple. | |
201 | </dd></dl> | |
202 | ||
203 | <P> | |
204 | ||
205 | <P> | |
206 | The following exceptions are the exceptions that are actually raised. | |
207 | ||
208 | <P> | |
209 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-286' xml:id='l2h-286' class="exception">AssertionError</tt></b></dt> | |
210 | <dd> | |
211 | <a id='l2h-287' xml:id='l2h-287'></a>Raised when an <tt class="keyword">assert</tt> statement fails. | |
212 | </dd></dl> | |
213 | ||
214 | <P> | |
215 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-288' xml:id='l2h-288' class="exception">AttributeError</tt></b></dt> | |
216 | <dd> | |
217 | Raised when an attribute reference or assignment fails. (When an | |
218 | object does not support attribute references or attribute assignments | |
219 | at all, <tt class="exception">TypeError</tt> is raised.) | |
220 | </dd></dl> | |
221 | ||
222 | <P> | |
223 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-289' xml:id='l2h-289' class="exception">EOFError</tt></b></dt> | |
224 | <dd> | |
225 | Raised when one of the built-in functions (<tt class="function">input()</tt> or | |
226 | <tt class="function">raw_input()</tt>) hits an end-of-file condition (EOF) without | |
227 | reading any data. | |
228 | (N.B.: the <tt class="method">read()</tt> and <tt class="method">readline()</tt> methods of file | |
229 | objects return an empty string when they hit EOF.) | |
230 | </dd></dl> | |
231 | ||
232 | <P> | |
233 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-290' xml:id='l2h-290' class="exception">FloatingPointError</tt></b></dt> | |
234 | <dd> | |
235 | Raised when a floating point operation fails. This exception is | |
236 | always defined, but can only be raised when Python is configured | |
237 | with the <b class="programopt">--with-fpectl</b> option, or the | |
238 | <tt class="constant">WANT_SIGFPE_HANDLER</tt> symbol is defined in the | |
239 | <span class="file">pyconfig.h</span> file. | |
240 | </dd></dl> | |
241 | ||
242 | <P> | |
243 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-291' xml:id='l2h-291' class="exception">IOError</tt></b></dt> | |
244 | <dd> | |
245 | Raised when an I/O operation (such as a <tt class="keyword">print</tt> statement, | |
246 | the built-in <tt class="function">open()</tt> function or a method of a file | |
247 | object) fails for an I/O-related reason, e.g., ``file not found'' or | |
248 | ``disk full''. | |
249 | ||
250 | <P> | |
251 | This class is derived from <tt class="exception">EnvironmentError</tt>. See the | |
252 | discussion above for more information on exception instance | |
253 | attributes. | |
254 | </dd></dl> | |
255 | ||
256 | <P> | |
257 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-292' xml:id='l2h-292' class="exception">ImportError</tt></b></dt> | |
258 | <dd> | |
259 | Raised when an <tt class="keyword">import</tt> statement fails to find the module | |
260 | definition or when a <code>from ... import</code> fails to find a | |
261 | name that is to be imported. | |
262 | </dd></dl> | |
263 | ||
264 | <P> | |
265 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-293' xml:id='l2h-293' class="exception">IndexError</tt></b></dt> | |
266 | <dd> | |
267 | Raised when a sequence subscript is out of range. (Slice indices are | |
268 | silently truncated to fall in the allowed range; if an index is not a | |
269 | plain integer, <tt class="exception">TypeError</tt> is raised.) | |
270 | </dd></dl> | |
271 | ||
272 | <P> | |
273 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-294' xml:id='l2h-294' class="exception">KeyError</tt></b></dt> | |
274 | <dd> | |
275 | Raised when a mapping (dictionary) key is not found in the set of | |
276 | existing keys. | |
277 | </dd></dl> | |
278 | ||
279 | <P> | |
280 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-295' xml:id='l2h-295' class="exception">KeyboardInterrupt</tt></b></dt> | |
281 | <dd> | |
282 | Raised when the user hits the interrupt key (normally | |
283 | <kbd>Control-C</kbd> or <kbd>Delete</kbd>). During execution, a check for | |
284 | interrupts is made regularly. | |
285 | Interrupts typed when a built-in function <tt class="function">input()</tt> or | |
286 | <tt class="function">raw_input()</tt> is waiting for input also raise this | |
287 | exception. | |
288 | </dd></dl> | |
289 | ||
290 | <P> | |
291 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-296' xml:id='l2h-296' class="exception">MemoryError</tt></b></dt> | |
292 | <dd> | |
293 | Raised when an operation runs out of memory but the situation may | |
294 | still be rescued (by deleting some objects). The associated value is | |
295 | a string indicating what kind of (internal) operation ran out of memory. | |
296 | Note that because of the underlying memory management architecture | |
297 | (C's <tt class="cfunction">malloc()</tt> function), the interpreter may not | |
298 | always be able to completely recover from this situation; it | |
299 | nevertheless raises an exception so that a stack traceback can be | |
300 | printed, in case a run-away program was the cause. | |
301 | </dd></dl> | |
302 | ||
303 | <P> | |
304 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-297' xml:id='l2h-297' class="exception">NameError</tt></b></dt> | |
305 | <dd> | |
306 | Raised when a local or global name is not found. This applies only | |
307 | to unqualified names. The associated value is an error message that | |
308 | includes the name that could not be found. | |
309 | </dd></dl> | |
310 | ||
311 | <P> | |
312 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-298' xml:id='l2h-298' class="exception">NotImplementedError</tt></b></dt> | |
313 | <dd> | |
314 | This exception is derived from <tt class="exception">RuntimeError</tt>. In user | |
315 | defined base classes, abstract methods should raise this exception | |
316 | when they require derived classes to override the method. | |
317 | ||
318 | <span class="versionnote">New in version 1.5.2.</span> | |
319 | ||
320 | </dd></dl> | |
321 | ||
322 | <P> | |
323 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-299' xml:id='l2h-299' class="exception">OSError</tt></b></dt> | |
324 | <dd> | |
325 | This class is derived from <tt class="exception">EnvironmentError</tt> and is used | |
326 | primarily as the <tt class="module"><a href="module-os.html">os</a></tt> module's <code>os.error</code> exception. | |
327 | See <tt class="exception">EnvironmentError</tt> above for a description of the | |
328 | possible associated values. | |
329 | ||
330 | <span class="versionnote">New in version 1.5.2.</span> | |
331 | ||
332 | </dd></dl> | |
333 | ||
334 | <P> | |
335 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-300' xml:id='l2h-300' class="exception">OverflowError</tt></b></dt> | |
336 | <dd> | |
337 | Raised when the result of an arithmetic operation is too large to be | |
338 | represented. This cannot occur for long integers (which would rather | |
339 | raise <tt class="exception">MemoryError</tt> than give up). Because of the lack of | |
340 | standardization of floating point exception handling in C, most | |
341 | floating point operations also aren't checked. For plain integers, | |
342 | all operations that can overflow are checked except left shift, where | |
343 | typical applications prefer to drop bits than raise an exception. | |
344 | </dd></dl> | |
345 | ||
346 | <P> | |
347 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-301' xml:id='l2h-301' class="exception">ReferenceError</tt></b></dt> | |
348 | <dd> | |
349 | This exception is raised when a weak reference proxy, created by the | |
350 | <tt class="function"><tt class="module"><a href="module-weakref.html">weakref</a></tt>.proxy()</tt> function, is used to access | |
351 | an attribute of the referent after it has been garbage collected. | |
352 | For more information on weak references, see the <tt class="module"><a href="module-weakref.html">weakref</a></tt> | |
353 | module. | |
354 | ||
355 | <span class="versionnote">New in version 2.2: | |
356 | Previously known as the | |
357 | <tt class="exception"><tt class="module"><a href="module-weakref.html">weakref</a></tt>.ReferenceError</tt> | |
358 | exception.</span> | |
359 | ||
360 | </dd></dl> | |
361 | ||
362 | <P> | |
363 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-302' xml:id='l2h-302' class="exception">RuntimeError</tt></b></dt> | |
364 | <dd> | |
365 | Raised when an error is detected that doesn't fall in any of the | |
366 | other categories. The associated value is a string indicating what | |
367 | precisely went wrong. (This exception is mostly a relic from a | |
368 | previous version of the interpreter; it is not used very much any | |
369 | more.) | |
370 | </dd></dl> | |
371 | ||
372 | <P> | |
373 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-303' xml:id='l2h-303' class="exception">StopIteration</tt></b></dt> | |
374 | <dd> | |
375 | Raised by an iterator's <tt class="method">next()</tt> method to signal that there | |
376 | are no further values. | |
377 | This is derived from <tt class="exception">Exception</tt> rather than | |
378 | <tt class="exception">StandardError</tt>, since this is not considered an error in | |
379 | its normal application. | |
380 | ||
381 | <span class="versionnote">New in version 2.2.</span> | |
382 | ||
383 | </dd></dl> | |
384 | ||
385 | <P> | |
386 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-304' xml:id='l2h-304' class="exception">SyntaxError</tt></b></dt> | |
387 | <dd> | |
388 | Raised when the parser encounters a syntax error. This may occur in | |
389 | an <tt class="keyword">import</tt> statement, in an <tt class="keyword">exec</tt> statement, in a call | |
390 | to the built-in function <tt class="function">eval()</tt> or <tt class="function">input()</tt>, or | |
391 | when reading the initial script or standard input (also | |
392 | interactively). | |
393 | ||
394 | <P> | |
395 | Instances of this class have attributes <tt class="member">filename</tt>, | |
396 | <tt class="member">lineno</tt>, <tt class="member">offset</tt> and <tt class="member">text</tt> for easier access | |
397 | to the details. <tt class="function">str()</tt> of the exception instance returns | |
398 | only the message. | |
399 | </dd></dl> | |
400 | ||
401 | <P> | |
402 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-305' xml:id='l2h-305' class="exception">SystemError</tt></b></dt> | |
403 | <dd> | |
404 | Raised when the interpreter finds an internal error, but the | |
405 | situation does not look so serious to cause it to abandon all hope. | |
406 | The associated value is a string indicating what went wrong (in | |
407 | low-level terms). | |
408 | ||
409 | <P> | |
410 | You should report this to the author or maintainer of your Python | |
411 | interpreter. Be sure to report the version of the Python | |
412 | interpreter (<code>sys.version</code>; it is also printed at the start of an | |
413 | interactive Python session), the exact error message (the exception's | |
414 | associated value) and if possible the source of the program that | |
415 | triggered the error. | |
416 | </dd></dl> | |
417 | ||
418 | <P> | |
419 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-306' xml:id='l2h-306' class="exception">SystemExit</tt></b></dt> | |
420 | <dd> | |
421 | This exception is raised by the <tt class="function">sys.exit()</tt> function. When it | |
422 | is not handled, the Python interpreter exits; no stack traceback is | |
423 | printed. If the associated value is a plain integer, it specifies the | |
424 | system exit status (passed to C's <tt class="cfunction">exit()</tt> function); if it is | |
425 | <code>None</code>, the exit status is zero; if it has another type (such as | |
426 | a string), the object's value is printed and the exit status is one. | |
427 | ||
428 | <P> | |
429 | Instances have an attribute <tt class="member">code</tt> which is set to the | |
430 | proposed exit status or error message (defaulting to <code>None</code>). | |
431 | Also, this exception derives directly from <tt class="exception">Exception</tt> and | |
432 | not <tt class="exception">StandardError</tt>, since it is not technically an error. | |
433 | ||
434 | <P> | |
435 | A call to <tt class="function">sys.exit()</tt> is translated into an exception so that | |
436 | clean-up handlers (<tt class="keyword">finally</tt> clauses of <tt class="keyword">try</tt> statements) | |
437 | can be executed, and so that a debugger can execute a script without | |
438 | running the risk of losing control. The <tt class="function">os._exit()</tt> function | |
439 | can be used if it is absolutely positively necessary to exit | |
440 | immediately (for example, in the child process after a call to | |
441 | <tt class="function">fork()</tt>). | |
442 | </dd></dl> | |
443 | ||
444 | <P> | |
445 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-307' xml:id='l2h-307' class="exception">TypeError</tt></b></dt> | |
446 | <dd> | |
447 | Raised when an operation or function is applied to an object | |
448 | of inappropriate type. The associated value is a string giving | |
449 | details about the type mismatch. | |
450 | </dd></dl> | |
451 | ||
452 | <P> | |
453 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-308' xml:id='l2h-308' class="exception">UnboundLocalError</tt></b></dt> | |
454 | <dd> | |
455 | Raised when a reference is made to a local variable in a function or | |
456 | method, but no value has been bound to that variable. This is a | |
457 | subclass of <tt class="exception">NameError</tt>. | |
458 | ||
459 | <span class="versionnote">New in version 2.0.</span> | |
460 | ||
461 | </dd></dl> | |
462 | ||
463 | <P> | |
464 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-309' xml:id='l2h-309' class="exception">UnicodeError</tt></b></dt> | |
465 | <dd> | |
466 | Raised when a Unicode-related encoding or decoding error occurs. It | |
467 | is a subclass of <tt class="exception">ValueError</tt>. | |
468 | ||
469 | <span class="versionnote">New in version 2.0.</span> | |
470 | ||
471 | </dd></dl> | |
472 | ||
473 | <P> | |
474 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-310' xml:id='l2h-310' class="exception">UnicodeEncodeError</tt></b></dt> | |
475 | <dd> | |
476 | Raised when a Unicode-related error occurs during encoding. It | |
477 | is a subclass of <tt class="exception">UnicodeError</tt>. | |
478 | ||
479 | <span class="versionnote">New in version 2.3.</span> | |
480 | ||
481 | </dd></dl> | |
482 | ||
483 | <P> | |
484 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-311' xml:id='l2h-311' class="exception">UnicodeDecodeError</tt></b></dt> | |
485 | <dd> | |
486 | Raised when a Unicode-related error occurs during decoding. It | |
487 | is a subclass of <tt class="exception">UnicodeError</tt>. | |
488 | ||
489 | <span class="versionnote">New in version 2.3.</span> | |
490 | ||
491 | </dd></dl> | |
492 | ||
493 | <P> | |
494 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-312' xml:id='l2h-312' class="exception">UnicodeTranslateError</tt></b></dt> | |
495 | <dd> | |
496 | Raised when a Unicode-related error occurs during translating. It | |
497 | is a subclass of <tt class="exception">UnicodeError</tt>. | |
498 | ||
499 | <span class="versionnote">New in version 2.3.</span> | |
500 | ||
501 | </dd></dl> | |
502 | ||
503 | <P> | |
504 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-313' xml:id='l2h-313' class="exception">ValueError</tt></b></dt> | |
505 | <dd> | |
506 | Raised when a built-in operation or function receives an argument | |
507 | that has the right type but an inappropriate value, and the | |
508 | situation is not described by a more precise exception such as | |
509 | <tt class="exception">IndexError</tt>. | |
510 | </dd></dl> | |
511 | ||
512 | <P> | |
513 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-314' xml:id='l2h-314' class="exception">WindowsError</tt></b></dt> | |
514 | <dd> | |
515 | Raised when a Windows-specific error occurs or when the error number | |
516 | does not correspond to an <tt class="cdata">errno</tt> value. The | |
517 | <tt class="member">errno</tt> and <tt class="member">strerror</tt> values are created from the | |
518 | return values of the <tt class="cfunction">GetLastError()</tt> and | |
519 | <tt class="cfunction">FormatMessage()</tt> functions from the Windows Platform API. | |
520 | This is a subclass of <tt class="exception">OSError</tt>. | |
521 | ||
522 | <span class="versionnote">New in version 2.0.</span> | |
523 | ||
524 | </dd></dl> | |
525 | ||
526 | <P> | |
527 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-315' xml:id='l2h-315' class="exception">ZeroDivisionError</tt></b></dt> | |
528 | <dd> | |
529 | Raised when the second argument of a division or modulo operation is | |
530 | zero. The associated value is a string indicating the type of the | |
531 | operands and the operation. | |
532 | </dd></dl> | |
533 | ||
534 | <P> | |
535 | ||
536 | <P> | |
537 | The following exceptions are used as warning categories; see the | |
538 | <tt class="module"><a href="module-warnings.html">warnings</a></tt> module for more information. | |
539 | ||
540 | <P> | |
541 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-316' xml:id='l2h-316' class="exception">Warning</tt></b></dt> | |
542 | <dd> | |
543 | Base class for warning categories. | |
544 | </dd></dl> | |
545 | ||
546 | <P> | |
547 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-317' xml:id='l2h-317' class="exception">UserWarning</tt></b></dt> | |
548 | <dd> | |
549 | Base class for warnings generated by user code. | |
550 | </dd></dl> | |
551 | ||
552 | <P> | |
553 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-318' xml:id='l2h-318' class="exception">DeprecationWarning</tt></b></dt> | |
554 | <dd> | |
555 | Base class for warnings about deprecated features. | |
556 | </dd></dl> | |
557 | ||
558 | <P> | |
559 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-319' xml:id='l2h-319' class="exception">PendingDeprecationWarning</tt></b></dt> | |
560 | <dd> | |
561 | Base class for warnings about features which will be deprecated in the future. | |
562 | </dd></dl> | |
563 | ||
564 | <P> | |
565 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-320' xml:id='l2h-320' class="exception">SyntaxWarning</tt></b></dt> | |
566 | <dd> | |
567 | Base class for warnings about dubious syntax | |
568 | </dd></dl> | |
569 | ||
570 | <P> | |
571 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-321' xml:id='l2h-321' class="exception">RuntimeWarning</tt></b></dt> | |
572 | <dd> | |
573 | Base class for warnings about dubious runtime behavior. | |
574 | </dd></dl> | |
575 | ||
576 | <P> | |
577 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-322' xml:id='l2h-322' class="exception">FutureWarning</tt></b></dt> | |
578 | <dd> | |
579 | Base class for warnings about constructs that will change semantically | |
580 | in the future. | |
581 | </dd></dl> | |
582 | ||
583 | <P> | |
584 | The class hierarchy for built-in exceptions is: | |
585 | ||
586 | <P> | |
587 | <div class="verbatim"><pre> | |
588 | Exception | |
589 | +-- SystemExit | |
590 | +-- StopIteration | |
591 | +-- StandardError | |
592 | | +-- KeyboardInterrupt | |
593 | | +-- ImportError | |
594 | | +-- EnvironmentError | |
595 | | | +-- IOError | |
596 | | | +-- OSError | |
597 | | | +-- WindowsError | |
598 | | +-- EOFError | |
599 | | +-- RuntimeError | |
600 | | | +-- NotImplementedError | |
601 | | +-- NameError | |
602 | | | +-- UnboundLocalError | |
603 | | +-- AttributeError | |
604 | | +-- SyntaxError | |
605 | | | +-- IndentationError | |
606 | | | +-- TabError | |
607 | | +-- TypeError | |
608 | | +-- AssertionError | |
609 | | +-- LookupError | |
610 | | | +-- IndexError | |
611 | | | +-- KeyError | |
612 | | +-- ArithmeticError | |
613 | | | +-- OverflowError | |
614 | | | +-- ZeroDivisionError | |
615 | | | +-- FloatingPointError | |
616 | | +-- ValueError | |
617 | | | +-- UnicodeError | |
618 | | | +-- UnicodeEncodeError | |
619 | | | +-- UnicodeDecodeError | |
620 | | | +-- UnicodeTranslateError | |
621 | | +-- ReferenceError | |
622 | | +-- SystemError | |
623 | | +-- MemoryError | |
624 | +---Warning | |
625 | +-- UserWarning | |
626 | +-- DeprecationWarning | |
627 | +-- PendingDeprecationWarning | |
628 | +-- SyntaxWarning | |
629 | +-- OverflowWarning (not generated in 2.4; won't exist in 2.5) | |
630 | +-- RuntimeWarning | |
631 | +-- FutureWarning | |
632 | </pre></div> | |
633 | ||
634 | <DIV CLASS="navigation"> | |
635 | <div class='online-navigation'> | |
636 | <p></p><hr /> | |
637 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
638 | <tr> | |
639 | <td class='online-navigation'><a rel="prev" title="2.3.11 Special Attributes" | |
640 | href="specialattrs.html"><img src='../icons/previous.png' | |
641 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
642 | <td class='online-navigation'><a rel="parent" title="2. Built-In Objects" | |
643 | href="builtin.html"><img src='../icons/up.png' | |
644 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
645 | <td class='online-navigation'><a rel="next" title="2.5 Built-in Constants" | |
646 | href="node35.html"><img src='../icons/next.png' | |
647 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
648 | <td align="center" width="100%">Python Library Reference</td> | |
649 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
650 | href="contents.html"><img src='../icons/contents.png' | |
651 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
652 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
653 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
654 | <td class='online-navigation'><a rel="index" title="Index" | |
655 | href="genindex.html"><img src='../icons/index.png' | |
656 | border='0' height='32' alt='Index' width='32' /></A></td> | |
657 | </tr></table> | |
658 | <div class='online-navigation'> | |
659 | <b class="navlabel">Previous:</b> | |
660 | <a class="sectref" rel="prev" href="specialattrs.html">2.3.11 Special Attributes</A> | |
661 | <b class="navlabel">Up:</b> | |
662 | <a class="sectref" rel="parent" href="builtin.html">2. Built-In Objects</A> | |
663 | <b class="navlabel">Next:</b> | |
664 | <a class="sectref" rel="next" href="node35.html">2.5 Built-in Constants</A> | |
665 | </div> | |
666 | </div> | |
667 | <hr /> | |
668 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
669 | </DIV> | |
670 | <!--End of Navigation Panel--> | |
671 | <ADDRESS> | |
672 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
673 | </ADDRESS> | |
674 | </BODY> | |
675 | </HTML> |