blob: 631c798a0e942d7c13f95bd9b8b37daed5eda763 [file] [log] [blame]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001\section{Built-in Exceptions}
Fred Drake3bd9ab01998-07-23 19:33:08 +00002
Fred Drakeffbe6871999-04-22 21:23:22 +00003\declaremodule{standard}{exceptions}
Andrew M. Kuchling032bd0a2003-05-13 14:13:58 +00004\modulesynopsis{Standard exception classes.}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00005
Fred Drakeb91e9341998-07-23 17:59:49 +00006
Neal Norwitz847207a2003-05-29 02:17:23 +00007Exceptions should be class objects.
Fred Drake7acb2182000-09-09 03:28:00 +00008The exceptions are defined in the module \module{exceptions}. This
9module never needs to be imported explicitly: the exceptions are
Fred Drakec6920552001-09-21 21:12:30 +000010provided in the built-in namespace as well as the \module{exceptions}
11module.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000012
Fred Drake38e5d272000-04-03 20:13:55 +000013For class exceptions, in a \keyword{try}\stindex{try} statement with
14an \keyword{except}\stindex{except} clause that mentions a particular
15class, that clause also handles any exception classes derived from
16that class (but not exception classes from which \emph{it} is
17derived). Two exception classes that are not related via subclassing
18are never equivalent, even if they have the same name.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000019
20The built-in exceptions listed below can be generated by the
21interpreter or built-in functions. Except where mentioned, they have
22an ``associated value'' indicating the detailed cause of the error.
23This may be a string or a tuple containing several items of
24information (e.g., an error code and a string explaining the code).
Fred Drake38e5d272000-04-03 20:13:55 +000025The associated value is the second argument to the
Guido van Rossum360e4b82007-05-14 22:51:27 +000026\keyword{raise}\stindex{raise} statement. If the exception class is
27derived from the standard root class \exception{BaseException}, the
28associated value is present as the exception instance's \member{args}
29attribute.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000030
31User code can raise built-in exceptions. This can be used to test an
Guido van Rossumdf3dba01997-10-05 18:51:26 +000032exception handler or to report an error condition ``just like'' the
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000033situation in which the interpreter raises the same exception; but
34beware that there is nothing to prevent user code from raising an
35inappropriate error.
36
Fred Drakec6920552001-09-21 21:12:30 +000037The built-in exception classes can be sub-classed to define new
38exceptions; programmers are encouraged to at least derive new
Brett Cannon54ac2942006-03-01 22:10:49 +000039exceptions from the \exception{Exception} class and not
40\exception{BaseException}. More
Fred Drakec6920552001-09-21 21:12:30 +000041information on defining exceptions is available in the
42\citetitle[../tut/tut.html]{Python Tutorial} under the heading
43``User-defined Exceptions.''
44
Fred Drake19479911998-02-13 06:58:54 +000045\setindexsubitem{(built-in exception base class)}
Guido van Rossumdf3dba01997-10-05 18:51:26 +000046
47The following exceptions are only used as base classes for other
Fred Drake5828ad62000-04-06 15:03:01 +000048exceptions.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000049
Brett Cannon54ac2942006-03-01 22:10:49 +000050\begin{excdesc}{BaseException}
51The base class for all built-in exceptions. It is not meant to be directly
52inherited by user-defined classes (for that use \exception{Exception}). If
53\function{str()} or \function{unicode()} is called on an instance of this
54class, the representation of the argument(s) to the instance are returned or
Guido van Rossum360e4b82007-05-14 22:51:27 +000055the emptry string when there were no arguments. All arguments are
56stored in \member{args} as a tuple.
Brett Cannon54ac2942006-03-01 22:10:49 +000057\versionadded{2.5}
Brett Cannon3096c532006-03-02 03:52:06 +000058\end{excdesc}
Brett Cannon54ac2942006-03-01 22:10:49 +000059
Guido van Rossumdf3dba01997-10-05 18:51:26 +000060\begin{excdesc}{Exception}
Brett Cannon54ac2942006-03-01 22:10:49 +000061All built-in, non-system-exiting exceptions are derived
Guido van Rossumdf3dba01997-10-05 18:51:26 +000062from this class. All user-defined exceptions should also be derived
Brett Cannon54ac2942006-03-01 22:10:49 +000063from this class.
Thomas Wouters477c8d52006-05-27 19:21:47 +000064\versionchanged[Changed to inherit from \exception{BaseException}]{2.5}
Guido van Rossumdf3dba01997-10-05 18:51:26 +000065\end{excdesc}
66
67\begin{excdesc}{StandardError}
Barry Warsawf2b45541999-02-24 00:27:14 +000068The base class for all built-in exceptions except
Brett Cannon54ac2942006-03-01 22:10:49 +000069\exception{StopIteration}, \exception{GeneratorExit},
70\exception{KeyboardInterrupt} and \exception{SystemExit}.
71\exception{StandardError} itself is derived from \exception{Exception}.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000072\end{excdesc}
73
74\begin{excdesc}{ArithmeticError}
75The base class for those built-in exceptions that are raised for
Fred Drake27467e41998-07-23 19:47:41 +000076various arithmetic errors: \exception{OverflowError},
77\exception{ZeroDivisionError}, \exception{FloatingPointError}.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000078\end{excdesc}
79
80\begin{excdesc}{LookupError}
Barry Warsawda00c871998-07-23 19:57:35 +000081The base class for the exceptions that are raised when a key or
Fred Drake27467e41998-07-23 19:47:41 +000082index used on a mapping or sequence is invalid: \exception{IndexError},
Fred Drake53143be2000-10-25 21:05:29 +000083\exception{KeyError}. This can be raised directly by
84\function{sys.setdefaultencoding()}.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000085\end{excdesc}
86
Barry Warsawda00c871998-07-23 19:57:35 +000087\begin{excdesc}{EnvironmentError}
88The base class for exceptions that
89can occur outside the Python system: \exception{IOError},
90\exception{OSError}. When exceptions of this type are created with a
912-tuple, the first item is available on the instance's \member{errno}
92attribute (it is assumed to be an error number), and the second item
93is available on the \member{strerror} attribute (it is usually the
94associated error message). The tuple itself is also available on the
95\member{args} attribute.
Fred Draked0bceee1999-02-02 18:00:40 +000096\versionadded{1.5.2}
Barry Warsawda00c871998-07-23 19:57:35 +000097
98When an \exception{EnvironmentError} exception is instantiated with a
993-tuple, the first two items are available as above, while the third
100item is available on the \member{filename} attribute. However, for
101backwards compatibility, the \member{args} attribute contains only a
1022-tuple of the first two constructor arguments.
103
104The \member{filename} attribute is \code{None} when this exception is
105created with other than 3 arguments. The \member{errno} and
106\member{strerror} attributes are also \code{None} when the instance was
107created with other than 2 or 3 arguments. In this last case,
108\member{args} contains the verbatim constructor arguments as a tuple.
109\end{excdesc}
110
Fred Drake88c023b2000-09-07 16:33:32 +0000111
Fred Drake19479911998-02-13 06:58:54 +0000112\setindexsubitem{(built-in exception)}
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000113
114The following exceptions are the exceptions that are actually raised.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000115
116\begin{excdesc}{AssertionError}
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000117\stindex{assert}
Fred Drake38e5d272000-04-03 20:13:55 +0000118Raised when an \keyword{assert} statement fails.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000119\end{excdesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000120
121\begin{excdesc}{AttributeError}
122% xref to attribute reference?
123 Raised when an attribute reference or assignment fails. (When an
Guido van Rossum470be141995-03-17 16:07:09 +0000124 object does not support attribute references or attribute assignments
Fred Drake27467e41998-07-23 19:47:41 +0000125 at all, \exception{TypeError} is raised.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000126\end{excdesc}
127
128\begin{excdesc}{EOFError}
129% XXXJH xrefs here
Neal Norwitzce96f692006-03-17 06:49:51 +0000130 Raised when attempting to read beyond the end of a file.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000131% XXXJH xrefs here
Fred Drake27467e41998-07-23 19:47:41 +0000132 (N.B.: the \method{read()} and \method{readline()} methods of file
Fred Drakec37b65e2001-11-28 07:26:15 +0000133 objects return an empty string when they hit \EOF.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000134\end{excdesc}
135
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000136\begin{excdesc}{FloatingPointError}
Fred Drakeb44e7531998-07-27 21:11:42 +0000137 Raised when a floating point operation fails. This exception is
138 always defined, but can only be raised when Python is configured
Fred Drakeee775a12000-04-11 19:46:40 +0000139 with the \longprogramopt{with-fpectl} option, or the
Fred Drakeb44e7531998-07-27 21:11:42 +0000140 \constant{WANT_SIGFPE_HANDLER} symbol is defined in the
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000141 \file{pyconfig.h} file.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000142\end{excdesc}
143
Brett Cannon3096c532006-03-02 03:52:06 +0000144\begin{excdesc}{GeneratorExit}
Brett Cannon54ac2942006-03-01 22:10:49 +0000145 Raise when a generator's \method{close()} method is called.
146 It directly inherits from \exception{Exception} instead of
147 \exception{StandardError} since it is technically not an error.
148 \versionadded{2.5}
Brett Cannon3096c532006-03-02 03:52:06 +0000149\end{excdesc}
Brett Cannon54ac2942006-03-01 22:10:49 +0000150
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000151\begin{excdesc}{IOError}
152% XXXJH xrefs here
Fred Drakeb44e7531998-07-27 21:11:42 +0000153 Raised when an I/O operation (such as a \keyword{print} statement,
154 the built-in \function{open()} function or a method of a file
155 object) fails for an I/O-related reason, e.g., ``file not found'' or
156 ``disk full''.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000157
Fred Drake02e18b41999-01-05 21:42:18 +0000158 This class is derived from \exception{EnvironmentError}. See the
Fred Drakeb44e7531998-07-27 21:11:42 +0000159 discussion above for more information on exception instance
160 attributes.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000161\end{excdesc}
162
163\begin{excdesc}{ImportError}
164% XXXJH xref to import statement?
Fred Drake27467e41998-07-23 19:47:41 +0000165 Raised when an \keyword{import} statement fails to find the module
Fred Drakef65e3231998-11-25 20:55:03 +0000166 definition or when a \code{from \textrm{\ldots} import} fails to find a
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000167 name that is to be imported.
168\end{excdesc}
169
170\begin{excdesc}{IndexError}
171% XXXJH xref to sequences
172 Raised when a sequence subscript is out of range. (Slice indices are
173 silently truncated to fall in the allowed range; if an index is not a
Fred Drake27467e41998-07-23 19:47:41 +0000174 plain integer, \exception{TypeError} is raised.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000175\end{excdesc}
176
177\begin{excdesc}{KeyError}
178% XXXJH xref to mapping objects?
179 Raised when a mapping (dictionary) key is not found in the set of
180 existing keys.
181\end{excdesc}
182
183\begin{excdesc}{KeyboardInterrupt}
184 Raised when the user hits the interrupt key (normally
Fred Drake682d5f32001-07-12 02:09:51 +0000185 \kbd{Control-C} or \kbd{Delete}). During execution, a check for
Fred Drake2a1cc3e1998-04-28 13:38:54 +0000186 interrupts is made regularly.
Brett Cannon54ac2942006-03-01 22:10:49 +0000187% XXX(hylton) xrefs here
Brett Cannon54ac2942006-03-01 22:10:49 +0000188 The exception inherits from \exception{BaseException} so as to not be
189 accidentally caught by code that catches \exception{Exception} and thus
190 prevent the interpreter from exiting.
191 \versionchanged[Changed to inherit from \exception{BaseException}]{2.5}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000192\end{excdesc}
193
194\begin{excdesc}{MemoryError}
195 Raised when an operation runs out of memory but the situation may
196 still be rescued (by deleting some objects). The associated value is
197 a string indicating what kind of (internal) operation ran out of memory.
198 Note that because of the underlying memory management architecture
Fred Drake5828ad62000-04-06 15:03:01 +0000199 (C's \cfunction{malloc()} function), the interpreter may not
Fred Drake27467e41998-07-23 19:47:41 +0000200 always be able to completely recover from this situation; it
201 nevertheless raises an exception so that a stack traceback can be
202 printed, in case a run-away program was the cause.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000203\end{excdesc}
204
205\begin{excdesc}{NameError}
206 Raised when a local or global name is not found. This applies only
Raymond Hettinger9240be22002-08-27 23:53:23 +0000207 to unqualified names. The associated value is an error message that
208 includes the name that could not be found.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000209\end{excdesc}
210
Barry Warsaw6d26f4b1998-12-01 19:48:04 +0000211\begin{excdesc}{NotImplementedError}
Barry Warsaw6d26f4b1998-12-01 19:48:04 +0000212 This exception is derived from \exception{RuntimeError}. In user
213 defined base classes, abstract methods should raise this exception
214 when they require derived classes to override the method.
Fred Draked0bceee1999-02-02 18:00:40 +0000215 \versionadded{1.5.2}
Barry Warsaw6d26f4b1998-12-01 19:48:04 +0000216\end{excdesc}
217
Barry Warsawda00c871998-07-23 19:57:35 +0000218\begin{excdesc}{OSError}
219 %xref for os module
Fred Drakec457ca71998-07-23 20:31:53 +0000220 This class is derived from \exception{EnvironmentError} and is used
Fred Drakeffbe6871999-04-22 21:23:22 +0000221 primarily as the \refmodule{os} module's \code{os.error} exception.
Fred Drake98be47e1999-02-01 16:17:40 +0000222 See \exception{EnvironmentError} above for a description of the
223 possible associated values.
Fred Draked0bceee1999-02-02 18:00:40 +0000224 \versionadded{1.5.2}
Barry Warsawda00c871998-07-23 19:57:35 +0000225\end{excdesc}
226
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000227\begin{excdesc}{OverflowError}
228% XXXJH reference to long's and/or int's?
229 Raised when the result of an arithmetic operation is too large to be
230 represented. This cannot occur for long integers (which would rather
Fred Drake27467e41998-07-23 19:47:41 +0000231 raise \exception{MemoryError} than give up). Because of the lack of
Fred Drake5828ad62000-04-06 15:03:01 +0000232 standardization of floating point exception handling in C, most
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000233 floating point operations also aren't checked. For plain integers,
234 all operations that can overflow are checked except left shift, where
235 typical applications prefer to drop bits than raise an exception.
236\end{excdesc}
237
Fred Drake8c2c3d32001-10-06 06:10:54 +0000238\begin{excdesc}{ReferenceError}
239 This exception is raised when a weak reference proxy, created by the
240 \function{\refmodule{weakref}.proxy()} function, is used to access
241 an attribute of the referent after it has been garbage collected.
242 For more information on weak references, see the \refmodule{weakref}
243 module.
244 \versionadded[Previously known as the
245 \exception{\refmodule{weakref}.ReferenceError}
246 exception]{2.2}
247\end{excdesc}
248
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000249\begin{excdesc}{RuntimeError}
250 Raised when an error is detected that doesn't fall in any of the
251 other categories. The associated value is a string indicating what
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000252 precisely went wrong. (This exception is mostly a relic from a
253 previous version of the interpreter; it is not used very much any
254 more.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000255\end{excdesc}
256
Fred Drake9cfe1822001-05-03 04:30:45 +0000257\begin{excdesc}{StopIteration}
Georg Brandla18af4e2007-04-21 15:47:16 +0000258 Raised by builtin \function{next()} and an iterator's \method{__next__()}
259 method to signal that there are no further values.
Fred Drake9cfe1822001-05-03 04:30:45 +0000260 This is derived from \exception{Exception} rather than
261 \exception{StandardError}, since this is not considered an error in
262 its normal application.
Fred Drakef42cc452001-05-03 04:39:10 +0000263 \versionadded{2.2}
Fred Drake9cfe1822001-05-03 04:30:45 +0000264\end{excdesc}
265
Brett Cannon54ac2942006-03-01 22:10:49 +0000266
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000267\begin{excdesc}{SyntaxError}
268% XXXJH xref to these functions?
269 Raised when the parser encounters a syntax error. This may occur in
Georg Brandl7cae87c2006-09-06 06:51:57 +0000270 an \keyword{import} statement, in a call to the built-in functions
271 \function{exec()}, \function{execfile()}, \function{eval()} or
272 \function{input()}, or when reading the initial script or standard
273 input (also interactively).
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000274
Raymond Hettinger68804312005-01-01 00:28:46 +0000275 Instances of this class have attributes \member{filename},
Fred Drakec6920552001-09-21 21:12:30 +0000276 \member{lineno}, \member{offset} and \member{text} for easier access
277 to the details. \function{str()} of the exception instance returns
278 only the message.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000279\end{excdesc}
280
281\begin{excdesc}{SystemError}
282 Raised when the interpreter finds an internal error, but the
283 situation does not look so serious to cause it to abandon all hope.
284 The associated value is a string indicating what went wrong (in
285 low-level terms).
286
287 You should report this to the author or maintainer of your Python
Fred Drakec6920552001-09-21 21:12:30 +0000288 interpreter. Be sure to report the version of the Python
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000289 interpreter (\code{sys.version}; it is also printed at the start of an
290 interactive Python session), the exact error message (the exception's
291 associated value) and if possible the source of the program that
292 triggered the error.
293\end{excdesc}
294
295\begin{excdesc}{SystemExit}
Brett Cannon54ac2942006-03-01 22:10:49 +0000296% XXX(hylton) xref to module sys?
Fred Drake27467e41998-07-23 19:47:41 +0000297 This exception is raised by the \function{sys.exit()} function. When it
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000298 is not handled, the Python interpreter exits; no stack traceback is
299 printed. If the associated value is a plain integer, it specifies the
Fred Drake5828ad62000-04-06 15:03:01 +0000300 system exit status (passed to C's \cfunction{exit()} function); if it is
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000301 \code{None}, the exit status is zero; if it has another type (such as
302 a string), the object's value is printed and the exit status is one.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000303
Fred Drake5828ad62000-04-06 15:03:01 +0000304 Instances have an attribute \member{code} which is set to the
305 proposed exit status or error message (defaulting to \code{None}).
Brett Cannon54ac2942006-03-01 22:10:49 +0000306 Also, this exception derives directly from \exception{BaseException} and
Fred Drake5828ad62000-04-06 15:03:01 +0000307 not \exception{StandardError}, since it is not technically an error.
308
Fred Drake27467e41998-07-23 19:47:41 +0000309 A call to \function{sys.exit()} is translated into an exception so that
310 clean-up handlers (\keyword{finally} clauses of \keyword{try} statements)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000311 can be executed, and so that a debugger can execute a script without
Fred Drake27467e41998-07-23 19:47:41 +0000312 running the risk of losing control. The \function{os._exit()} function
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000313 can be used if it is absolutely positively necessary to exit
Fred Drakec046e972001-07-23 19:19:39 +0000314 immediately (for example, in the child process after a call to
315 \function{fork()}).
Brett Cannon54ac2942006-03-01 22:10:49 +0000316
317 The exception inherits from \exception{BaseException} instead of
318 \exception{StandardError} or \exception{Exception} so that it is not
319 accidentally caught by code that catches \exception{Exception}. This allows
320 the exception to properly propagate up and cause the interpreter to exit.
321 \versionchanged[Changed to inherit from \exception{BaseException}]{2.5}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000322\end{excdesc}
323
324\begin{excdesc}{TypeError}
Raymond Hettinger4ee2ff32003-08-04 08:33:50 +0000325 Raised when an operation or function is applied to an object
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000326 of inappropriate type. The associated value is a string giving
327 details about the type mismatch.
328\end{excdesc}
329
Fred Drake5828ad62000-04-06 15:03:01 +0000330\begin{excdesc}{UnboundLocalError}
331 Raised when a reference is made to a local variable in a function or
332 method, but no value has been bound to that variable. This is a
333 subclass of \exception{NameError}.
Fred Drake30f76ff2000-06-30 16:06:19 +0000334\versionadded{2.0}
Fred Drake5828ad62000-04-06 15:03:01 +0000335\end{excdesc}
336
Fred Drake3cb793e2000-04-06 14:48:35 +0000337\begin{excdesc}{UnicodeError}
338 Raised when a Unicode-related encoding or decoding error occurs. It
339 is a subclass of \exception{ValueError}.
Fred Drake30f76ff2000-06-30 16:06:19 +0000340\versionadded{2.0}
Fred Drake3cb793e2000-04-06 14:48:35 +0000341\end{excdesc}
342
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000343\begin{excdesc}{UnicodeEncodeError}
344 Raised when a Unicode-related error occurs during encoding. It
345 is a subclass of \exception{UnicodeError}.
346\versionadded{2.3}
347\end{excdesc}
348
349\begin{excdesc}{UnicodeDecodeError}
350 Raised when a Unicode-related error occurs during decoding. It
351 is a subclass of \exception{UnicodeError}.
352\versionadded{2.3}
353\end{excdesc}
354
355\begin{excdesc}{UnicodeTranslateError}
356 Raised when a Unicode-related error occurs during translating. It
357 is a subclass of \exception{UnicodeError}.
358\versionadded{2.3}
359\end{excdesc}
360
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000361\begin{excdesc}{ValueError}
362 Raised when a built-in operation or function receives an argument
363 that has the right type but an inappropriate value, and the
364 situation is not described by a more precise exception such as
Fred Drake27467e41998-07-23 19:47:41 +0000365 \exception{IndexError}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000366\end{excdesc}
367
Fred Drakecebda6f2000-04-17 17:42:00 +0000368\begin{excdesc}{WindowsError}
369 Raised when a Windows-specific error occurs or when the error number
370 does not correspond to an \cdata{errno} value. The
Thomas Wouters477c8d52006-05-27 19:21:47 +0000371 \member{winerror} and \member{strerror} values are created from the
Fred Drakecebda6f2000-04-17 17:42:00 +0000372 return values of the \cfunction{GetLastError()} and
373 \cfunction{FormatMessage()} functions from the Windows Platform API.
Thomas Wouters477c8d52006-05-27 19:21:47 +0000374 The \member{errno} value maps the \member{winerror} value to
375 corresponding \code{errno.h} values.
Fred Drakecebda6f2000-04-17 17:42:00 +0000376 This is a subclass of \exception{OSError}.
Fred Drake30f76ff2000-06-30 16:06:19 +0000377\versionadded{2.0}
Thomas Wouters477c8d52006-05-27 19:21:47 +0000378\versionchanged[Previous versions put the \cfunction{GetLastError()}
379codes into \member{errno}]{2.5}
Fred Drakecebda6f2000-04-17 17:42:00 +0000380\end{excdesc}
381
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000382\begin{excdesc}{ZeroDivisionError}
383 Raised when the second argument of a division or modulo operation is
384 zero. The associated value is a string indicating the type of the
385 operands and the operation.
386\end{excdesc}
Guido van Rossum1367b832000-12-19 04:27:54 +0000387
388
Fred Drakec6920552001-09-21 21:12:30 +0000389\setindexsubitem{(built-in warning)}
Guido van Rossum1367b832000-12-19 04:27:54 +0000390
391The following exceptions are used as warning categories; see the
Barry Warsawb8c20a72002-08-14 16:40:54 +0000392\refmodule{warnings} module for more information.
Guido van Rossum1367b832000-12-19 04:27:54 +0000393
394\begin{excdesc}{Warning}
395Base class for warning categories.
396\end{excdesc}
397
398\begin{excdesc}{UserWarning}
399Base class for warnings generated by user code.
400\end{excdesc}
401
402\begin{excdesc}{DeprecationWarning}
403Base class for warnings about deprecated features.
404\end{excdesc}
405
Neal Norwitzd68f5172002-05-29 15:54:55 +0000406\begin{excdesc}{PendingDeprecationWarning}
407Base class for warnings about features which will be deprecated in the future.
408\end{excdesc}
409
Guido van Rossum1367b832000-12-19 04:27:54 +0000410\begin{excdesc}{SyntaxWarning}
411Base class for warnings about dubious syntax
412\end{excdesc}
413
414\begin{excdesc}{RuntimeWarning}
415Base class for warnings about dubious runtime behavior.
416\end{excdesc}
Skip Montanarobb6bbc42002-03-28 20:53:22 +0000417
Barry Warsawb8c20a72002-08-14 16:40:54 +0000418\begin{excdesc}{FutureWarning}
419Base class for warnings about constructs that will change semantically
420in the future.
421\end{excdesc}
422
Thomas Wouters477c8d52006-05-27 19:21:47 +0000423\begin{excdesc}{ImportWarning}
424Base class for warnings about probable mistakes in module imports.
425\versionadded{2.5}
426\end{excdesc}
427
Thomas Wouters00ee7ba2006-08-21 19:07:27 +0000428\begin{excdesc}{UnicodeWarning}
429Base class for warnings related to Unicode.
430\versionadded{2.5}
431\end{excdesc}
432
Fred Drake8d62e942002-03-28 21:06:17 +0000433The class hierarchy for built-in exceptions is:
Skip Montanarobb6bbc42002-03-28 20:53:22 +0000434
Brett Cannon54ac2942006-03-01 22:10:49 +0000435\verbatiminput{../../Lib/test/exception_hierarchy.txt}