blob: acefb43725e175f1862384b8c7237b77b17d2835 [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
Neal Norwitz847207a2003-05-29 02:17:23 +000013\begin{notice}
14In past versions of Python string exceptions were supported. In
15Python 1.5 and newer versions, all standard exceptions have been
16converted to class objects and users are encouraged to do the same.
17String exceptions will raise a \code{PendingDeprecationWarning}.
18In future versions, support for string exceptions will be removed.
19
Guido van Rossumdf3dba01997-10-05 18:51:26 +000020Two distinct string objects with the same value are considered different
21exceptions. This is done to force programmers to use exception names
22rather than their string value when specifying exception handlers.
23The string value of all built-in exceptions is their name, but this is
24not a requirement for user-defined exceptions or exceptions defined by
25library modules.
Neal Norwitz847207a2003-05-29 02:17:23 +000026\end{notice}
Guido van Rossumdf3dba01997-10-05 18:51:26 +000027
Fred Drake38e5d272000-04-03 20:13:55 +000028For class exceptions, in a \keyword{try}\stindex{try} statement with
29an \keyword{except}\stindex{except} clause that mentions a particular
30class, that clause also handles any exception classes derived from
31that class (but not exception classes from which \emph{it} is
32derived). Two exception classes that are not related via subclassing
33are never equivalent, even if they have the same name.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000034
35The built-in exceptions listed below can be generated by the
36interpreter or built-in functions. Except where mentioned, they have
37an ``associated value'' indicating the detailed cause of the error.
38This may be a string or a tuple containing several items of
39information (e.g., an error code and a string explaining the code).
Fred Drake38e5d272000-04-03 20:13:55 +000040The associated value is the second argument to the
41\keyword{raise}\stindex{raise} statement. For string exceptions, the
42associated value itself will be stored in the variable named as the
43second argument of the \keyword{except} clause (if any). For class
44exceptions, that variable receives the exception instance. If the
45exception class is derived from the standard root class
46\exception{Exception}, the associated value is present as the
47exception instance's \member{args} attribute, and possibly on other
48attributes as well.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000049
50User code can raise built-in exceptions. This can be used to test an
Guido van Rossumdf3dba01997-10-05 18:51:26 +000051exception handler or to report an error condition ``just like'' the
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000052situation in which the interpreter raises the same exception; but
53beware that there is nothing to prevent user code from raising an
54inappropriate error.
55
Fred Drakec6920552001-09-21 21:12:30 +000056The built-in exception classes can be sub-classed to define new
57exceptions; programmers are encouraged to at least derive new
58exceptions from the \exception{Exception} base class. More
59information on defining exceptions is available in the
60\citetitle[../tut/tut.html]{Python Tutorial} under the heading
61``User-defined Exceptions.''
62
Fred Drake19479911998-02-13 06:58:54 +000063\setindexsubitem{(built-in exception base class)}
Guido van Rossumdf3dba01997-10-05 18:51:26 +000064
65The following exceptions are only used as base classes for other
Fred Drake5828ad62000-04-06 15:03:01 +000066exceptions.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000067
68\begin{excdesc}{Exception}
69The root class for exceptions. All built-in exceptions are derived
70from this class. All user-defined exceptions should also be derived
Fred Drake27467e41998-07-23 19:47:41 +000071from this class, but this is not (yet) enforced. The \function{str()}
Guido van Rossumdf3dba01997-10-05 18:51:26 +000072function, when applied to an instance of this class (or most derived
73classes) returns the string value of the argument or arguments, or an
Guido van Rossum6cd7ecb1997-10-07 14:41:04 +000074empty string if no arguments were given to the constructor. When used
75as a sequence, this accesses the arguments given to the constructor
Barry Warsawda00c871998-07-23 19:57:35 +000076(handy for backward compatibility with old code). The arguments are
Fred Drakec457ca71998-07-23 20:31:53 +000077also available on the instance's \member{args} attribute, as a tuple.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000078\end{excdesc}
79
80\begin{excdesc}{StandardError}
Barry Warsawf2b45541999-02-24 00:27:14 +000081The base class for all built-in exceptions except
Fred Drakec046e972001-07-23 19:19:39 +000082\exception{StopIteration} and \exception{SystemExit}.
83\exception{StandardError} itself is derived from the root class
Fred Drake27467e41998-07-23 19:47:41 +000084\exception{Exception}.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000085\end{excdesc}
86
87\begin{excdesc}{ArithmeticError}
88The base class for those built-in exceptions that are raised for
Fred Drake27467e41998-07-23 19:47:41 +000089various arithmetic errors: \exception{OverflowError},
90\exception{ZeroDivisionError}, \exception{FloatingPointError}.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000091\end{excdesc}
92
93\begin{excdesc}{LookupError}
Barry Warsawda00c871998-07-23 19:57:35 +000094The base class for the exceptions that are raised when a key or
Fred Drake27467e41998-07-23 19:47:41 +000095index used on a mapping or sequence is invalid: \exception{IndexError},
Fred Drake53143be2000-10-25 21:05:29 +000096\exception{KeyError}. This can be raised directly by
97\function{sys.setdefaultencoding()}.
Guido van Rossumdf3dba01997-10-05 18:51:26 +000098\end{excdesc}
99
Barry Warsawda00c871998-07-23 19:57:35 +0000100\begin{excdesc}{EnvironmentError}
101The base class for exceptions that
102can occur outside the Python system: \exception{IOError},
103\exception{OSError}. When exceptions of this type are created with a
1042-tuple, the first item is available on the instance's \member{errno}
105attribute (it is assumed to be an error number), and the second item
106is available on the \member{strerror} attribute (it is usually the
107associated error message). The tuple itself is also available on the
108\member{args} attribute.
Fred Draked0bceee1999-02-02 18:00:40 +0000109\versionadded{1.5.2}
Barry Warsawda00c871998-07-23 19:57:35 +0000110
111When an \exception{EnvironmentError} exception is instantiated with a
1123-tuple, the first two items are available as above, while the third
113item is available on the \member{filename} attribute. However, for
114backwards compatibility, the \member{args} attribute contains only a
1152-tuple of the first two constructor arguments.
116
117The \member{filename} attribute is \code{None} when this exception is
118created with other than 3 arguments. The \member{errno} and
119\member{strerror} attributes are also \code{None} when the instance was
120created with other than 2 or 3 arguments. In this last case,
121\member{args} contains the verbatim constructor arguments as a tuple.
122\end{excdesc}
123
Fred Drake88c023b2000-09-07 16:33:32 +0000124
Fred Drake19479911998-02-13 06:58:54 +0000125\setindexsubitem{(built-in exception)}
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000126
127The following exceptions are the exceptions that are actually raised.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000128
129\begin{excdesc}{AssertionError}
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000130\stindex{assert}
Fred Drake38e5d272000-04-03 20:13:55 +0000131Raised when an \keyword{assert} statement fails.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000132\end{excdesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000133
134\begin{excdesc}{AttributeError}
135% xref to attribute reference?
136 Raised when an attribute reference or assignment fails. (When an
Guido van Rossum470be141995-03-17 16:07:09 +0000137 object does not support attribute references or attribute assignments
Fred Drake27467e41998-07-23 19:47:41 +0000138 at all, \exception{TypeError} is raised.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000139\end{excdesc}
140
141\begin{excdesc}{EOFError}
142% XXXJH xrefs here
Fred Drake27467e41998-07-23 19:47:41 +0000143 Raised when one of the built-in functions (\function{input()} or
Fred Drakec37b65e2001-11-28 07:26:15 +0000144 \function{raw_input()}) hits an end-of-file condition (\EOF) without
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000145 reading any data.
146% XXXJH xrefs here
Fred Drake27467e41998-07-23 19:47:41 +0000147 (N.B.: the \method{read()} and \method{readline()} methods of file
Fred Drakec37b65e2001-11-28 07:26:15 +0000148 objects return an empty string when they hit \EOF.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000149\end{excdesc}
150
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000151\begin{excdesc}{FloatingPointError}
Fred Drakeb44e7531998-07-27 21:11:42 +0000152 Raised when a floating point operation fails. This exception is
153 always defined, but can only be raised when Python is configured
Fred Drakeee775a12000-04-11 19:46:40 +0000154 with the \longprogramopt{with-fpectl} option, or the
Fred Drakeb44e7531998-07-27 21:11:42 +0000155 \constant{WANT_SIGFPE_HANDLER} symbol is defined in the
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000156 \file{pyconfig.h} file.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000157\end{excdesc}
158
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000159\begin{excdesc}{IOError}
160% XXXJH xrefs here
Fred Drakeb44e7531998-07-27 21:11:42 +0000161 Raised when an I/O operation (such as a \keyword{print} statement,
162 the built-in \function{open()} function or a method of a file
163 object) fails for an I/O-related reason, e.g., ``file not found'' or
164 ``disk full''.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000165
Fred Drake02e18b41999-01-05 21:42:18 +0000166 This class is derived from \exception{EnvironmentError}. See the
Fred Drakeb44e7531998-07-27 21:11:42 +0000167 discussion above for more information on exception instance
168 attributes.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000169\end{excdesc}
170
171\begin{excdesc}{ImportError}
172% XXXJH xref to import statement?
Fred Drake27467e41998-07-23 19:47:41 +0000173 Raised when an \keyword{import} statement fails to find the module
Fred Drakef65e3231998-11-25 20:55:03 +0000174 definition or when a \code{from \textrm{\ldots} import} fails to find a
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000175 name that is to be imported.
176\end{excdesc}
177
178\begin{excdesc}{IndexError}
179% XXXJH xref to sequences
180 Raised when a sequence subscript is out of range. (Slice indices are
181 silently truncated to fall in the allowed range; if an index is not a
Fred Drake27467e41998-07-23 19:47:41 +0000182 plain integer, \exception{TypeError} is raised.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000183\end{excdesc}
184
185\begin{excdesc}{KeyError}
186% XXXJH xref to mapping objects?
187 Raised when a mapping (dictionary) key is not found in the set of
188 existing keys.
189\end{excdesc}
190
191\begin{excdesc}{KeyboardInterrupt}
192 Raised when the user hits the interrupt key (normally
Fred Drake682d5f32001-07-12 02:09:51 +0000193 \kbd{Control-C} or \kbd{Delete}). During execution, a check for
Fred Drake2a1cc3e1998-04-28 13:38:54 +0000194 interrupts is made regularly.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000195% XXXJH xrefs here
Fred Drake2a1cc3e1998-04-28 13:38:54 +0000196 Interrupts typed when a built-in function \function{input()} or
Raymond Hettingerb4c1d9b2003-05-10 08:51:28 +0000197 \function{raw_input()} is waiting for input also raise this
Barry Warsawda00c871998-07-23 19:57:35 +0000198 exception.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000199\end{excdesc}
200
201\begin{excdesc}{MemoryError}
202 Raised when an operation runs out of memory but the situation may
203 still be rescued (by deleting some objects). The associated value is
204 a string indicating what kind of (internal) operation ran out of memory.
205 Note that because of the underlying memory management architecture
Fred Drake5828ad62000-04-06 15:03:01 +0000206 (C's \cfunction{malloc()} function), the interpreter may not
Fred Drake27467e41998-07-23 19:47:41 +0000207 always be able to completely recover from this situation; it
208 nevertheless raises an exception so that a stack traceback can be
209 printed, in case a run-away program was the cause.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000210\end{excdesc}
211
212\begin{excdesc}{NameError}
213 Raised when a local or global name is not found. This applies only
Raymond Hettinger9240be22002-08-27 23:53:23 +0000214 to unqualified names. The associated value is an error message that
215 includes the name that could not be found.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000216\end{excdesc}
217
Barry Warsaw6d26f4b1998-12-01 19:48:04 +0000218\begin{excdesc}{NotImplementedError}
Barry Warsaw6d26f4b1998-12-01 19:48:04 +0000219 This exception is derived from \exception{RuntimeError}. In user
220 defined base classes, abstract methods should raise this exception
221 when they require derived classes to override the method.
Fred Draked0bceee1999-02-02 18:00:40 +0000222 \versionadded{1.5.2}
Barry Warsaw6d26f4b1998-12-01 19:48:04 +0000223\end{excdesc}
224
Barry Warsawda00c871998-07-23 19:57:35 +0000225\begin{excdesc}{OSError}
226 %xref for os module
Fred Drakec457ca71998-07-23 20:31:53 +0000227 This class is derived from \exception{EnvironmentError} and is used
Fred Drakeffbe6871999-04-22 21:23:22 +0000228 primarily as the \refmodule{os} module's \code{os.error} exception.
Fred Drake98be47e1999-02-01 16:17:40 +0000229 See \exception{EnvironmentError} above for a description of the
230 possible associated values.
Fred Draked0bceee1999-02-02 18:00:40 +0000231 \versionadded{1.5.2}
Barry Warsawda00c871998-07-23 19:57:35 +0000232\end{excdesc}
233
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000234\begin{excdesc}{OverflowError}
235% XXXJH reference to long's and/or int's?
236 Raised when the result of an arithmetic operation is too large to be
237 represented. This cannot occur for long integers (which would rather
Fred Drake27467e41998-07-23 19:47:41 +0000238 raise \exception{MemoryError} than give up). Because of the lack of
Fred Drake5828ad62000-04-06 15:03:01 +0000239 standardization of floating point exception handling in C, most
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000240 floating point operations also aren't checked. For plain integers,
241 all operations that can overflow are checked except left shift, where
242 typical applications prefer to drop bits than raise an exception.
243\end{excdesc}
244
Fred Drake8c2c3d32001-10-06 06:10:54 +0000245\begin{excdesc}{ReferenceError}
246 This exception is raised when a weak reference proxy, created by the
247 \function{\refmodule{weakref}.proxy()} function, is used to access
248 an attribute of the referent after it has been garbage collected.
249 For more information on weak references, see the \refmodule{weakref}
250 module.
251 \versionadded[Previously known as the
252 \exception{\refmodule{weakref}.ReferenceError}
253 exception]{2.2}
254\end{excdesc}
255
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000256\begin{excdesc}{RuntimeError}
257 Raised when an error is detected that doesn't fall in any of the
258 other categories. The associated value is a string indicating what
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000259 precisely went wrong. (This exception is mostly a relic from a
260 previous version of the interpreter; it is not used very much any
261 more.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000262\end{excdesc}
263
Fred Drake9cfe1822001-05-03 04:30:45 +0000264\begin{excdesc}{StopIteration}
265 Raised by an iterator's \method{next()} method to signal that there
266 are no further values.
267 This is derived from \exception{Exception} rather than
268 \exception{StandardError}, since this is not considered an error in
269 its normal application.
Fred Drakef42cc452001-05-03 04:39:10 +0000270 \versionadded{2.2}
Fred Drake9cfe1822001-05-03 04:30:45 +0000271\end{excdesc}
272
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000273\begin{excdesc}{SyntaxError}
274% XXXJH xref to these functions?
275 Raised when the parser encounters a syntax error. This may occur in
Fred Drake27467e41998-07-23 19:47:41 +0000276 an \keyword{import} statement, in an \keyword{exec} statement, in a call
277 to the built-in function \function{eval()} or \function{input()}, or
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000278 when reading the initial script or standard input (also
279 interactively).
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000280
Raymond Hettinger68804312005-01-01 00:28:46 +0000281 Instances of this class have attributes \member{filename},
Fred Drakec6920552001-09-21 21:12:30 +0000282 \member{lineno}, \member{offset} and \member{text} for easier access
283 to the details. \function{str()} of the exception instance returns
284 only the message.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000285\end{excdesc}
286
287\begin{excdesc}{SystemError}
288 Raised when the interpreter finds an internal error, but the
289 situation does not look so serious to cause it to abandon all hope.
290 The associated value is a string indicating what went wrong (in
291 low-level terms).
292
293 You should report this to the author or maintainer of your Python
Fred Drakec6920552001-09-21 21:12:30 +0000294 interpreter. Be sure to report the version of the Python
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000295 interpreter (\code{sys.version}; it is also printed at the start of an
296 interactive Python session), the exact error message (the exception's
297 associated value) and if possible the source of the program that
298 triggered the error.
299\end{excdesc}
300
301\begin{excdesc}{SystemExit}
302% XXXJH xref to module sys?
Fred Drake27467e41998-07-23 19:47:41 +0000303 This exception is raised by the \function{sys.exit()} function. When it
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000304 is not handled, the Python interpreter exits; no stack traceback is
305 printed. If the associated value is a plain integer, it specifies the
Fred Drake5828ad62000-04-06 15:03:01 +0000306 system exit status (passed to C's \cfunction{exit()} function); if it is
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000307 \code{None}, the exit status is zero; if it has another type (such as
308 a string), the object's value is printed and the exit status is one.
Guido van Rossumdf3dba01997-10-05 18:51:26 +0000309
Fred Drake5828ad62000-04-06 15:03:01 +0000310 Instances have an attribute \member{code} which is set to the
311 proposed exit status or error message (defaulting to \code{None}).
312 Also, this exception derives directly from \exception{Exception} and
313 not \exception{StandardError}, since it is not technically an error.
314
Fred Drake27467e41998-07-23 19:47:41 +0000315 A call to \function{sys.exit()} is translated into an exception so that
316 clean-up handlers (\keyword{finally} clauses of \keyword{try} statements)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000317 can be executed, and so that a debugger can execute a script without
Fred Drake27467e41998-07-23 19:47:41 +0000318 running the risk of losing control. The \function{os._exit()} function
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000319 can be used if it is absolutely positively necessary to exit
Fred Drakec046e972001-07-23 19:19:39 +0000320 immediately (for example, in the child process after a call to
321 \function{fork()}).
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
371 \member{errno} and \member{strerror} values are created from the
372 return values of the \cfunction{GetLastError()} and
373 \cfunction{FormatMessage()} functions from the Windows Platform API.
374 This is a subclass of \exception{OSError}.
Fred Drake30f76ff2000-06-30 16:06:19 +0000375\versionadded{2.0}
Fred Drakecebda6f2000-04-17 17:42:00 +0000376\end{excdesc}
377
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000378\begin{excdesc}{ZeroDivisionError}
379 Raised when the second argument of a division or modulo operation is
380 zero. The associated value is a string indicating the type of the
381 operands and the operation.
382\end{excdesc}
Guido van Rossum1367b832000-12-19 04:27:54 +0000383
384
Fred Drakec6920552001-09-21 21:12:30 +0000385\setindexsubitem{(built-in warning)}
Guido van Rossum1367b832000-12-19 04:27:54 +0000386
387The following exceptions are used as warning categories; see the
Barry Warsawb8c20a72002-08-14 16:40:54 +0000388\refmodule{warnings} module for more information.
Guido van Rossum1367b832000-12-19 04:27:54 +0000389
390\begin{excdesc}{Warning}
391Base class for warning categories.
392\end{excdesc}
393
394\begin{excdesc}{UserWarning}
395Base class for warnings generated by user code.
396\end{excdesc}
397
398\begin{excdesc}{DeprecationWarning}
399Base class for warnings about deprecated features.
400\end{excdesc}
401
Neal Norwitzd68f5172002-05-29 15:54:55 +0000402\begin{excdesc}{PendingDeprecationWarning}
403Base class for warnings about features which will be deprecated in the future.
404\end{excdesc}
405
Guido van Rossum1367b832000-12-19 04:27:54 +0000406\begin{excdesc}{SyntaxWarning}
407Base class for warnings about dubious syntax
408\end{excdesc}
409
410\begin{excdesc}{RuntimeWarning}
411Base class for warnings about dubious runtime behavior.
412\end{excdesc}
Skip Montanarobb6bbc42002-03-28 20:53:22 +0000413
Barry Warsawb8c20a72002-08-14 16:40:54 +0000414\begin{excdesc}{FutureWarning}
415Base class for warnings about constructs that will change semantically
416in the future.
417\end{excdesc}
418
Fred Drake8d62e942002-03-28 21:06:17 +0000419The class hierarchy for built-in exceptions is:
Skip Montanarobb6bbc42002-03-28 20:53:22 +0000420
421\begin{verbatim}
422 Exception
423 +-- SystemExit
424 +-- StopIteration
425 +-- StandardError
426 | +-- KeyboardInterrupt
427 | +-- ImportError
428 | +-- EnvironmentError
429 | | +-- IOError
430 | | +-- OSError
431 | | +-- WindowsError
432 | +-- EOFError
433 | +-- RuntimeError
434 | | +-- NotImplementedError
435 | +-- NameError
436 | | +-- UnboundLocalError
437 | +-- AttributeError
438 | +-- SyntaxError
439 | | +-- IndentationError
440 | | +-- TabError
441 | +-- TypeError
442 | +-- AssertionError
443 | +-- LookupError
444 | | +-- IndexError
445 | | +-- KeyError
446 | +-- ArithmeticError
447 | | +-- OverflowError
448 | | +-- ZeroDivisionError
449 | | +-- FloatingPointError
450 | +-- ValueError
451 | | +-- UnicodeError
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000452 | | +-- UnicodeEncodeError
453 | | +-- UnicodeDecodeError
454 | | +-- UnicodeTranslateError
Skip Montanarobb6bbc42002-03-28 20:53:22 +0000455 | +-- ReferenceError
456 | +-- SystemError
457 | +-- MemoryError
458 +---Warning
459 +-- UserWarning
460 +-- DeprecationWarning
Neal Norwitzd68f5172002-05-29 15:54:55 +0000461 +-- PendingDeprecationWarning
Skip Montanarobb6bbc42002-03-28 20:53:22 +0000462 +-- SyntaxWarning
Tim Petersc8854432004-08-25 02:14:08 +0000463 +-- OverflowWarning (not generated in 2.4; won't exist in 2.5)
Skip Montanarobb6bbc42002-03-28 20:53:22 +0000464 +-- RuntimeWarning
Barry Warsawb8c20a72002-08-14 16:40:54 +0000465 +-- FutureWarning
Skip Montanarobb6bbc42002-03-28 20:53:22 +0000466\end{verbatim}