blob: b793fd39d5dcdd67c4366fe8fc2f242119059da0 [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
26\keyword{raise}\stindex{raise} statement. For string exceptions, the
27associated value itself will be stored in the variable named as the
28second argument of the \keyword{except} clause (if any). For class
29exceptions, that variable receives the exception instance. If the
30exception class is derived from the standard root class
Brett Cannon54ac2942006-03-01 22:10:49 +000031\exception{BaseException}, the associated value is present as the
32exception instance's \member{args} attribute. If there is a single argument
33(as is preferred), it is bound to the \member{message} attribute.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000034
35User code can raise built-in exceptions. This can be used to test an
Guido van Rossumdf3dba01997-10-05 18:51:26 +000036exception handler or to report an error condition ``just like'' the
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000037situation in which the interpreter raises the same exception; but
38beware that there is nothing to prevent user code from raising an
39inappropriate error.
40
Fred Drakec6920552001-09-21 21:12:30 +000041The built-in exception classes can be sub-classed to define new
42exceptions; programmers are encouraged to at least derive new
Brett Cannon54ac2942006-03-01 22:10:49 +000043exceptions from the \exception{Exception} class and not
44\exception{BaseException}. More
Fred Drakec6920552001-09-21 21:12:30 +000045information on defining exceptions is available in the
46\citetitle[../tut/tut.html]{Python Tutorial} under the heading
47``User-defined Exceptions.''
48
Fred Drake19479911998-02-13 06:58:54 +000049\setindexsubitem{(built-in exception base class)}
Guido van Rossumdf3dba01997-10-05 18:51:26 +000050
51The following exceptions are only used as base classes for other
Fred Drake5828ad62000-04-06 15:03:01 +000052exceptions.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000053
Brett Cannon54ac2942006-03-01 22:10:49 +000054\begin{excdesc}{BaseException}
55The base class for all built-in exceptions. It is not meant to be directly
56inherited by user-defined classes (for that use \exception{Exception}). If
57\function{str()} or \function{unicode()} is called on an instance of this
58class, the representation of the argument(s) to the instance are returned or
59the emptry string when there were no arguments. If only a single argument is
60passed in, it is stored in the \member{message} attribute. If more than one
61argument is passed in, \member{message} is set to the empty string. These
62semantics are meant to reflect the fact that \member{message} is to store a
63text message explaining why the exception had been raised. If more data needs
64to be attached to the exception, attach it through arbitrary attributes on the
65instance. All arguments are also stored in \member{args} as a tuple, but it will
66eventually be deprecated and thus its use is discouraged.
Brett Cannon54ac2942006-03-01 22:10:49 +000067\versionadded{2.5}
Brett Cannon3096c532006-03-02 03:52:06 +000068\end{excdesc}
Brett Cannon54ac2942006-03-01 22:10:49 +000069
Guido van Rossumdf3dba01997-10-05 18:51:26 +000070\begin{excdesc}{Exception}
Brett Cannon54ac2942006-03-01 22:10:49 +000071All built-in, non-system-exiting exceptions are derived
Guido van Rossumdf3dba01997-10-05 18:51:26 +000072from this class. All user-defined exceptions should also be derived
Brett Cannon54ac2942006-03-01 22:10:49 +000073from this class.
George Yoshida2f6ce532006-05-16 18:07:00 +000074\versionchanged[Changed to inherit from \exception{BaseException}]{2.5}
Guido van Rossumdf3dba01997-10-05 18:51:26 +000075\end{excdesc}
76
77\begin{excdesc}{StandardError}
Barry Warsawf2b45541999-02-24 00:27:14 +000078The base class for all built-in exceptions except
Brett Cannon54ac2942006-03-01 22:10:49 +000079\exception{StopIteration}, \exception{GeneratorExit},
80\exception{KeyboardInterrupt} and \exception{SystemExit}.
81\exception{StandardError} itself is derived from \exception{Exception}.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000082\end{excdesc}
83
84\begin{excdesc}{ArithmeticError}
85The base class for those built-in exceptions that are raised for
Fred Drake27467e41998-07-23 19:47:41 +000086various arithmetic errors: \exception{OverflowError},
87\exception{ZeroDivisionError}, \exception{FloatingPointError}.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000088\end{excdesc}
89
90\begin{excdesc}{LookupError}
Barry Warsawda00c871998-07-23 19:57:35 +000091The base class for the exceptions that are raised when a key or
Fred Drake27467e41998-07-23 19:47:41 +000092index used on a mapping or sequence is invalid: \exception{IndexError},
Fred Drake53143be2000-10-25 21:05:29 +000093\exception{KeyError}. This can be raised directly by
94\function{sys.setdefaultencoding()}.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000095\end{excdesc}
96
Barry Warsawda00c871998-07-23 19:57:35 +000097\begin{excdesc}{EnvironmentError}
98The base class for exceptions that
99can occur outside the Python system: \exception{IOError},
100\exception{OSError}. When exceptions of this type are created with a
1012-tuple, the first item is available on the instance's \member{errno}
102attribute (it is assumed to be an error number), and the second item
103is available on the \member{strerror} attribute (it is usually the
104associated error message). The tuple itself is also available on the
105\member{args} attribute.
Fred Draked0bceee1999-02-02 18:00:40 +0000106\versionadded{1.5.2}
Barry Warsawda00c871998-07-23 19:57:35 +0000107
108When an \exception{EnvironmentError} exception is instantiated with a
1093-tuple, the first two items are available as above, while the third
110item is available on the \member{filename} attribute. However, for
111backwards compatibility, the \member{args} attribute contains only a
1122-tuple of the first two constructor arguments.
113
114The \member{filename} attribute is \code{None} when this exception is
115created with other than 3 arguments. The \member{errno} and
116\member{strerror} attributes are also \code{None} when the instance was
117created with other than 2 or 3 arguments. In this last case,
118\member{args} contains the verbatim constructor arguments as a tuple.
119\end{excdesc}
120
Fred Drake88c023b2000-09-07 16:33:32 +0000121
Fred Drake19479911998-02-13 06:58:54 +0000122\setindexsubitem{(built-in exception)}
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000123
124The following exceptions are the exceptions that are actually raised.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000125
126\begin{excdesc}{AssertionError}
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000127\stindex{assert}
Fred Drake38e5d272000-04-03 20:13:55 +0000128Raised when an \keyword{assert} statement fails.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000129\end{excdesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000130
131\begin{excdesc}{AttributeError}
132% xref to attribute reference?
133 Raised when an attribute reference or assignment fails. (When an
Guido van Rossum470be141995-03-17 16:07:09 +0000134 object does not support attribute references or attribute assignments
Fred Drake27467e41998-07-23 19:47:41 +0000135 at all, \exception{TypeError} is raised.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000136\end{excdesc}
137
138\begin{excdesc}{EOFError}
139% XXXJH xrefs here
Fred Drake27467e41998-07-23 19:47:41 +0000140 Raised when one of the built-in functions (\function{input()} or
Fred Drakec37b65e2001-11-28 07:26:15 +0000141 \function{raw_input()}) hits an end-of-file condition (\EOF) without
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000142 reading any data.
143% XXXJH xrefs here
Fred Drake27467e41998-07-23 19:47:41 +0000144 (N.B.: the \method{read()} and \method{readline()} methods of file
Fred Drakec37b65e2001-11-28 07:26:15 +0000145 objects return an empty string when they hit \EOF.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000146\end{excdesc}
147
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000148\begin{excdesc}{FloatingPointError}
Fred Drakeb44e7531998-07-27 21:11:42 +0000149 Raised when a floating point operation fails. This exception is
150 always defined, but can only be raised when Python is configured
Fred Drakeee775a12000-04-11 19:46:40 +0000151 with the \longprogramopt{with-fpectl} option, or the
Fred Drakeb44e7531998-07-27 21:11:42 +0000152 \constant{WANT_SIGFPE_HANDLER} symbol is defined in the
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000153 \file{pyconfig.h} file.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000154\end{excdesc}
155
Brett Cannon3096c532006-03-02 03:52:06 +0000156\begin{excdesc}{GeneratorExit}
Brett Cannon54ac2942006-03-01 22:10:49 +0000157 Raise when a generator's \method{close()} method is called.
158 It directly inherits from \exception{Exception} instead of
159 \exception{StandardError} since it is technically not an error.
160 \versionadded{2.5}
Brett Cannon3096c532006-03-02 03:52:06 +0000161\end{excdesc}
Brett Cannon54ac2942006-03-01 22:10:49 +0000162
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000163\begin{excdesc}{IOError}
164% XXXJH xrefs here
Fred Drakeb44e7531998-07-27 21:11:42 +0000165 Raised when an I/O operation (such as a \keyword{print} statement,
166 the built-in \function{open()} function or a method of a file
167 object) fails for an I/O-related reason, e.g., ``file not found'' or
168 ``disk full''.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000169
Fred Drake02e18b41999-01-05 21:42:18 +0000170 This class is derived from \exception{EnvironmentError}. See the
Fred Drakeb44e7531998-07-27 21:11:42 +0000171 discussion above for more information on exception instance
172 attributes.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000173\end{excdesc}
174
175\begin{excdesc}{ImportError}
176% XXXJH xref to import statement?
Fred Drake27467e41998-07-23 19:47:41 +0000177 Raised when an \keyword{import} statement fails to find the module
Fred Drakef65e3231998-11-25 20:55:03 +0000178 definition or when a \code{from \textrm{\ldots} import} fails to find a
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000179 name that is to be imported.
180\end{excdesc}
181
182\begin{excdesc}{IndexError}
183% XXXJH xref to sequences
184 Raised when a sequence subscript is out of range. (Slice indices are
185 silently truncated to fall in the allowed range; if an index is not a
Fred Drake27467e41998-07-23 19:47:41 +0000186 plain integer, \exception{TypeError} is raised.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000187\end{excdesc}
188
189\begin{excdesc}{KeyError}
190% XXXJH xref to mapping objects?
191 Raised when a mapping (dictionary) key is not found in the set of
192 existing keys.
193\end{excdesc}
194
195\begin{excdesc}{KeyboardInterrupt}
196 Raised when the user hits the interrupt key (normally
Fred Drake682d5f32001-07-12 02:09:51 +0000197 \kbd{Control-C} or \kbd{Delete}). During execution, a check for
Fred Drake2a1cc3e1998-04-28 13:38:54 +0000198 interrupts is made regularly.
Brett Cannon54ac2942006-03-01 22:10:49 +0000199% XXX(hylton) xrefs here
Fred Drake2a1cc3e1998-04-28 13:38:54 +0000200 Interrupts typed when a built-in function \function{input()} or
Raymond Hettingerb4c1d9b2003-05-10 08:51:28 +0000201 \function{raw_input()} is waiting for input also raise this
Barry Warsawda00c871998-07-23 19:57:35 +0000202 exception.
Brett Cannon54ac2942006-03-01 22:10:49 +0000203 The exception inherits from \exception{BaseException} so as to not be
204 accidentally caught by code that catches \exception{Exception} and thus
205 prevent the interpreter from exiting.
206 \versionchanged[Changed to inherit from \exception{BaseException}]{2.5}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000207\end{excdesc}
208
209\begin{excdesc}{MemoryError}
210 Raised when an operation runs out of memory but the situation may
211 still be rescued (by deleting some objects). The associated value is
212 a string indicating what kind of (internal) operation ran out of memory.
213 Note that because of the underlying memory management architecture
Fred Drake5828ad62000-04-06 15:03:01 +0000214 (C's \cfunction{malloc()} function), the interpreter may not
Fred Drake27467e41998-07-23 19:47:41 +0000215 always be able to completely recover from this situation; it
216 nevertheless raises an exception so that a stack traceback can be
217 printed, in case a run-away program was the cause.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000218\end{excdesc}
219
220\begin{excdesc}{NameError}
221 Raised when a local or global name is not found. This applies only
Raymond Hettinger9240be22002-08-27 23:53:23 +0000222 to unqualified names. The associated value is an error message that
223 includes the name that could not be found.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000224\end{excdesc}
225
Barry Warsaw6d26f4b1998-12-01 19:48:04 +0000226\begin{excdesc}{NotImplementedError}
Barry Warsaw6d26f4b1998-12-01 19:48:04 +0000227 This exception is derived from \exception{RuntimeError}. In user
228 defined base classes, abstract methods should raise this exception
229 when they require derived classes to override the method.
Fred Draked0bceee1999-02-02 18:00:40 +0000230 \versionadded{1.5.2}
Barry Warsaw6d26f4b1998-12-01 19:48:04 +0000231\end{excdesc}
232
Barry Warsawda00c871998-07-23 19:57:35 +0000233\begin{excdesc}{OSError}
234 %xref for os module
Fred Drakec457ca71998-07-23 20:31:53 +0000235 This class is derived from \exception{EnvironmentError} and is used
Fred Drakeffbe6871999-04-22 21:23:22 +0000236 primarily as the \refmodule{os} module's \code{os.error} exception.
Fred Drake98be47e1999-02-01 16:17:40 +0000237 See \exception{EnvironmentError} above for a description of the
238 possible associated values.
Fred Draked0bceee1999-02-02 18:00:40 +0000239 \versionadded{1.5.2}
Barry Warsawda00c871998-07-23 19:57:35 +0000240\end{excdesc}
241
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000242\begin{excdesc}{OverflowError}
243% XXXJH reference to long's and/or int's?
244 Raised when the result of an arithmetic operation is too large to be
245 represented. This cannot occur for long integers (which would rather
Fred Drake27467e41998-07-23 19:47:41 +0000246 raise \exception{MemoryError} than give up). Because of the lack of
Fred Drake5828ad62000-04-06 15:03:01 +0000247 standardization of floating point exception handling in C, most
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000248 floating point operations also aren't checked. For plain integers,
249 all operations that can overflow are checked except left shift, where
250 typical applications prefer to drop bits than raise an exception.
251\end{excdesc}
252
Fred Drake8c2c3d32001-10-06 06:10:54 +0000253\begin{excdesc}{ReferenceError}
254 This exception is raised when a weak reference proxy, created by the
255 \function{\refmodule{weakref}.proxy()} function, is used to access
256 an attribute of the referent after it has been garbage collected.
257 For more information on weak references, see the \refmodule{weakref}
258 module.
259 \versionadded[Previously known as the
260 \exception{\refmodule{weakref}.ReferenceError}
261 exception]{2.2}
262\end{excdesc}
263
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000264\begin{excdesc}{RuntimeError}
265 Raised when an error is detected that doesn't fall in any of the
266 other categories. The associated value is a string indicating what
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000267 precisely went wrong. (This exception is mostly a relic from a
268 previous version of the interpreter; it is not used very much any
269 more.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000270\end{excdesc}
271
Fred Drake9cfe1822001-05-03 04:30:45 +0000272\begin{excdesc}{StopIteration}
273 Raised by an iterator's \method{next()} method to signal that there
274 are no further values.
275 This is derived from \exception{Exception} rather than
276 \exception{StandardError}, since this is not considered an error in
277 its normal application.
Fred Drakef42cc452001-05-03 04:39:10 +0000278 \versionadded{2.2}
Fred Drake9cfe1822001-05-03 04:30:45 +0000279\end{excdesc}
280
Brett Cannon54ac2942006-03-01 22:10:49 +0000281
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000282\begin{excdesc}{SyntaxError}
283% XXXJH xref to these functions?
284 Raised when the parser encounters a syntax error. This may occur in
Fred Drake27467e41998-07-23 19:47:41 +0000285 an \keyword{import} statement, in an \keyword{exec} statement, in a call
286 to the built-in function \function{eval()} or \function{input()}, or
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000287 when reading the initial script or standard input (also
288 interactively).
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000289
Raymond Hettinger68804312005-01-01 00:28:46 +0000290 Instances of this class have attributes \member{filename},
Fred Drakec6920552001-09-21 21:12:30 +0000291 \member{lineno}, \member{offset} and \member{text} for easier access
292 to the details. \function{str()} of the exception instance returns
293 only the message.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000294\end{excdesc}
295
296\begin{excdesc}{SystemError}
297 Raised when the interpreter finds an internal error, but the
298 situation does not look so serious to cause it to abandon all hope.
299 The associated value is a string indicating what went wrong (in
300 low-level terms).
301
302 You should report this to the author or maintainer of your Python
Fred Drakec6920552001-09-21 21:12:30 +0000303 interpreter. Be sure to report the version of the Python
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000304 interpreter (\code{sys.version}; it is also printed at the start of an
305 interactive Python session), the exact error message (the exception's
306 associated value) and if possible the source of the program that
307 triggered the error.
308\end{excdesc}
309
310\begin{excdesc}{SystemExit}
Brett Cannon54ac2942006-03-01 22:10:49 +0000311% XXX(hylton) xref to module sys?
Fred Drake27467e41998-07-23 19:47:41 +0000312 This exception is raised by the \function{sys.exit()} function. When it
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000313 is not handled, the Python interpreter exits; no stack traceback is
314 printed. If the associated value is a plain integer, it specifies the
Fred Drake5828ad62000-04-06 15:03:01 +0000315 system exit status (passed to C's \cfunction{exit()} function); if it is
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000316 \code{None}, the exit status is zero; if it has another type (such as
317 a string), the object's value is printed and the exit status is one.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000318
Fred Drake5828ad62000-04-06 15:03:01 +0000319 Instances have an attribute \member{code} which is set to the
320 proposed exit status or error message (defaulting to \code{None}).
Brett Cannon54ac2942006-03-01 22:10:49 +0000321 Also, this exception derives directly from \exception{BaseException} and
Fred Drake5828ad62000-04-06 15:03:01 +0000322 not \exception{StandardError}, since it is not technically an error.
323
Fred Drake27467e41998-07-23 19:47:41 +0000324 A call to \function{sys.exit()} is translated into an exception so that
325 clean-up handlers (\keyword{finally} clauses of \keyword{try} statements)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000326 can be executed, and so that a debugger can execute a script without
Fred Drake27467e41998-07-23 19:47:41 +0000327 running the risk of losing control. The \function{os._exit()} function
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000328 can be used if it is absolutely positively necessary to exit
Fred Drakec046e972001-07-23 19:19:39 +0000329 immediately (for example, in the child process after a call to
330 \function{fork()}).
Brett Cannon54ac2942006-03-01 22:10:49 +0000331
332 The exception inherits from \exception{BaseException} instead of
333 \exception{StandardError} or \exception{Exception} so that it is not
334 accidentally caught by code that catches \exception{Exception}. This allows
335 the exception to properly propagate up and cause the interpreter to exit.
336 \versionchanged[Changed to inherit from \exception{BaseException}]{2.5}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000337\end{excdesc}
338
339\begin{excdesc}{TypeError}
Raymond Hettinger4ee2ff32003-08-04 08:33:50 +0000340 Raised when an operation or function is applied to an object
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000341 of inappropriate type. The associated value is a string giving
342 details about the type mismatch.
343\end{excdesc}
344
Fred Drake5828ad62000-04-06 15:03:01 +0000345\begin{excdesc}{UnboundLocalError}
346 Raised when a reference is made to a local variable in a function or
347 method, but no value has been bound to that variable. This is a
348 subclass of \exception{NameError}.
Fred Drake30f76ff2000-06-30 16:06:19 +0000349\versionadded{2.0}
Fred Drake5828ad62000-04-06 15:03:01 +0000350\end{excdesc}
351
Fred Drake3cb793e2000-04-06 14:48:35 +0000352\begin{excdesc}{UnicodeError}
353 Raised when a Unicode-related encoding or decoding error occurs. It
354 is a subclass of \exception{ValueError}.
Fred Drake30f76ff2000-06-30 16:06:19 +0000355\versionadded{2.0}
Fred Drake3cb793e2000-04-06 14:48:35 +0000356\end{excdesc}
357
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000358\begin{excdesc}{UnicodeEncodeError}
359 Raised when a Unicode-related error occurs during encoding. It
360 is a subclass of \exception{UnicodeError}.
361\versionadded{2.3}
362\end{excdesc}
363
364\begin{excdesc}{UnicodeDecodeError}
365 Raised when a Unicode-related error occurs during decoding. It
366 is a subclass of \exception{UnicodeError}.
367\versionadded{2.3}
368\end{excdesc}
369
370\begin{excdesc}{UnicodeTranslateError}
371 Raised when a Unicode-related error occurs during translating. It
372 is a subclass of \exception{UnicodeError}.
373\versionadded{2.3}
374\end{excdesc}
375
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000376\begin{excdesc}{ValueError}
377 Raised when a built-in operation or function receives an argument
378 that has the right type but an inappropriate value, and the
379 situation is not described by a more precise exception such as
Fred Drake27467e41998-07-23 19:47:41 +0000380 \exception{IndexError}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000381\end{excdesc}
382
Fred Drakecebda6f2000-04-17 17:42:00 +0000383\begin{excdesc}{WindowsError}
384 Raised when a Windows-specific error occurs or when the error number
385 does not correspond to an \cdata{errno} value. The
Martin v. Löwis879768d2006-05-11 13:28:43 +0000386 \member{winerror} and \member{strerror} values are created from the
Fred Drakecebda6f2000-04-17 17:42:00 +0000387 return values of the \cfunction{GetLastError()} and
388 \cfunction{FormatMessage()} functions from the Windows Platform API.
Martin v. Löwis879768d2006-05-11 13:28:43 +0000389 The \member{errno} value maps the \member{winerror} value to
390 corresponding \code{errno.h} values.
Fred Drakecebda6f2000-04-17 17:42:00 +0000391 This is a subclass of \exception{OSError}.
Fred Drake30f76ff2000-06-30 16:06:19 +0000392\versionadded{2.0}
Martin v. Löwis879768d2006-05-11 13:28:43 +0000393\versionchanged[Previous versions put the \cfunction{GetLastError()}
394codes into \member{errno}]{2.5}
Fred Drakecebda6f2000-04-17 17:42:00 +0000395\end{excdesc}
396
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000397\begin{excdesc}{ZeroDivisionError}
398 Raised when the second argument of a division or modulo operation is
399 zero. The associated value is a string indicating the type of the
400 operands and the operation.
401\end{excdesc}
Guido van Rossum1367b832000-12-19 04:27:54 +0000402
403
Fred Drakec6920552001-09-21 21:12:30 +0000404\setindexsubitem{(built-in warning)}
Guido van Rossum1367b832000-12-19 04:27:54 +0000405
406The following exceptions are used as warning categories; see the
Barry Warsawb8c20a72002-08-14 16:40:54 +0000407\refmodule{warnings} module for more information.
Guido van Rossum1367b832000-12-19 04:27:54 +0000408
409\begin{excdesc}{Warning}
410Base class for warning categories.
411\end{excdesc}
412
413\begin{excdesc}{UserWarning}
414Base class for warnings generated by user code.
415\end{excdesc}
416
417\begin{excdesc}{DeprecationWarning}
418Base class for warnings about deprecated features.
419\end{excdesc}
420
Neal Norwitzd68f5172002-05-29 15:54:55 +0000421\begin{excdesc}{PendingDeprecationWarning}
422Base class for warnings about features which will be deprecated in the future.
423\end{excdesc}
424
Guido van Rossum1367b832000-12-19 04:27:54 +0000425\begin{excdesc}{SyntaxWarning}
426Base class for warnings about dubious syntax
427\end{excdesc}
428
429\begin{excdesc}{RuntimeWarning}
430Base class for warnings about dubious runtime behavior.
431\end{excdesc}
Skip Montanarobb6bbc42002-03-28 20:53:22 +0000432
Barry Warsawb8c20a72002-08-14 16:40:54 +0000433\begin{excdesc}{FutureWarning}
434Base class for warnings about constructs that will change semantically
435in the future.
436\end{excdesc}
437
George Yoshida0c8d7b02006-05-16 18:26:10 +0000438\begin{excdesc}{ImportWarning}
439Base class for warnings about probable mistakes in module imports.
440\versionadded{2.5}
441\end{excdesc}
442
Marc-André Lemburg040f76b2006-08-14 10:55:19 +0000443\begin{excdesc}{UnicodeWarning}
444Base class for warnings related to Unicode.
445\versionadded{2.5}
446\end{excdesc}
447
Fred Drake8d62e942002-03-28 21:06:17 +0000448The class hierarchy for built-in exceptions is:
Skip Montanarobb6bbc42002-03-28 20:53:22 +0000449
Brett Cannon54ac2942006-03-01 22:10:49 +0000450\verbatiminput{../../Lib/test/exception_hierarchy.txt}