blob: 33bc3b06deed17656aff9e227a26886abd409a25 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001.. _bltin-exceptions:
2
3Built-in Exceptions
4===================
5
Georg Brandl116aa622007-08-15 14:28:22 +00006.. index::
7 statement: try
8 statement: except
9
Georg Brandlfbd1b222009-12-29 21:38:35 +000010In Python, all exceptions must be instances of a class that derives from
11:class:`BaseException`. In a :keyword:`try` statement with an :keyword:`except`
Georg Brandl116aa622007-08-15 14:28:22 +000012clause that mentions a particular class, that clause also handles any exception
13classes derived from that class (but not exception classes from which *it* is
14derived). Two exception classes that are not related via subclassing are never
15equivalent, even if they have the same name.
16
17.. index:: statement: raise
18
19The built-in exceptions listed below can be generated by the interpreter or
20built-in functions. Except where mentioned, they have an "associated value"
Georg Brandlfb6fd5d2011-01-07 18:28:45 +000021indicating the detailed cause of the error. This may be a string or a tuple of
22several items of information (e.g., an error code and a string explaining the
23code). The associated value is usually passed as arguments to the exception
24class's constructor.
Georg Brandl116aa622007-08-15 14:28:22 +000025
26User code can raise built-in exceptions. This can be used to test an exception
27handler or to report an error condition "just like" the situation in which the
28interpreter raises the same exception; but beware that there is nothing to
29prevent user code from raising an inappropriate error.
30
31The built-in exception classes can be sub-classed to define new exceptions;
32programmers are encouraged to at least derive new exceptions from the
33:exc:`Exception` class and not :exc:`BaseException`. More information on
34defining exceptions is available in the Python Tutorial under
35:ref:`tut-userexceptions`.
36
Nick Coghlanab7bf212012-02-26 17:49:52 +100037When raising (or re-raising) an exception in an :keyword:`except` clause
38:attr:`__context__` is automatically set to the last exception caught; if the
39new exception is not handled the traceback that is eventually displayed will
40include the originating exception(s) and the final exception.
41
42This implicit exception chain can be made explicit by using :keyword:`from`
43with :keyword:`raise`. The single argument to :keyword:`from` must be an
Benjamin Petersonad8586d2012-02-27 10:59:10 -050044exception or :const:`None`, and it will be set as :attr:`__cause__` on the
Nick Coghlanab7bf212012-02-26 17:49:52 +100045raised exception. If :attr:`__cause__` is an exception it will be displayed
46instead of :attr:`__context__`; if :attr:`__cause__` is None,
47:attr:`__context__` will not be displayed by the default exception handling
48code. (Note: the default value for :attr:`__context__` is :const:`None`,
49while the default value for :attr:`__cause__` is :const:`Ellipsis`.)
50
51In either case, the default exception handling code will not display
52any of the remaining links in the :attr:`__context__` chain if
53:attr:`__cause__` has been set.
54
Antoine Pitrouf9c77462011-10-12 16:02:00 +020055
56Base classes
57------------
58
Georg Brandlfbd1b222009-12-29 21:38:35 +000059The following exceptions are used mostly as base classes for other exceptions.
Georg Brandl116aa622007-08-15 14:28:22 +000060
Georg Brandl116aa622007-08-15 14:28:22 +000061.. exception:: BaseException
62
63 The base class for all built-in exceptions. It is not meant to be directly
Georg Brandlfb6fd5d2011-01-07 18:28:45 +000064 inherited by user-defined classes (for that, use :exc:`Exception`). If
Amaury Forgeot d'Arc3b1acf12011-11-22 19:34:08 +010065 :func:`str` is called on an instance of this class, the representation of
66 the argument(s) to the instance are returned, or the empty string when
67 there were no arguments.
Georg Brandlfb6fd5d2011-01-07 18:28:45 +000068
69 .. attribute:: args
70
71 The tuple of arguments given to the exception constructor. Some built-in
72 exceptions (like :exc:`IOError`) expect a certain number of arguments and
73 assign a special meaning to the elements of this tuple, while others are
74 usually called only with a single string giving an error message.
75
76 .. method:: with_traceback(tb)
77
78 This method sets *tb* as the new traceback for the exception and returns
79 the exception object. It is usually used in exception handling code like
80 this::
81
82 try:
83 ...
84 except SomeException:
85 tb = sys.exc_info()[2]
86 raise OtherException(...).with_traceback(tb)
Georg Brandl116aa622007-08-15 14:28:22 +000087
Georg Brandl116aa622007-08-15 14:28:22 +000088
89.. exception:: Exception
90
91 All built-in, non-system-exiting exceptions are derived from this class. All
92 user-defined exceptions should also be derived from this class.
93
Georg Brandl116aa622007-08-15 14:28:22 +000094
95.. exception:: ArithmeticError
96
97 The base class for those built-in exceptions that are raised for various
98 arithmetic errors: :exc:`OverflowError`, :exc:`ZeroDivisionError`,
99 :exc:`FloatingPointError`.
100
101
Georg Brandl0bdfbfa2010-12-18 17:51:28 +0000102.. exception:: BufferError
103
104 Raised when a :ref:`buffer <bufferobjects>` related operation cannot be
105 performed.
106
107
Georg Brandl116aa622007-08-15 14:28:22 +0000108.. exception:: LookupError
109
Benjamin Petersonfa0d7032009-06-01 22:42:33 +0000110 The base class for the exceptions that are raised when a key or index used on
111 a mapping or sequence is invalid: :exc:`IndexError`, :exc:`KeyError`. This
112 can be raised directly by :func:`codecs.lookup`.
Georg Brandl116aa622007-08-15 14:28:22 +0000113
114
Antoine Pitrouf9c77462011-10-12 16:02:00 +0200115Concrete exceptions
116-------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000117
Georg Brandlfbd1b222009-12-29 21:38:35 +0000118The following exceptions are the exceptions that are usually raised.
Georg Brandl116aa622007-08-15 14:28:22 +0000119
120.. exception:: AssertionError
121
122 .. index:: statement: assert
123
124 Raised when an :keyword:`assert` statement fails.
125
126
127.. exception:: AttributeError
128
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000129 Raised when an attribute reference (see :ref:`attribute-references`) or
130 assignment fails. (When an object does not support attribute references or
131 attribute assignments at all, :exc:`TypeError` is raised.)
Georg Brandl116aa622007-08-15 14:28:22 +0000132
133
134.. exception:: EOFError
135
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000136 Raised when one of the built-in functions (:func:`input` or :func:`raw_input`)
137 hits an end-of-file condition (EOF) without reading any data. (N.B.: the
Georg Brandl81ac1ce2007-08-31 17:17:17 +0000138 :meth:`file.read` and :meth:`file.readline` methods return an empty string
139 when they hit EOF.)
Georg Brandl116aa622007-08-15 14:28:22 +0000140
141
142.. exception:: FloatingPointError
143
144 Raised when a floating point operation fails. This exception is always defined,
145 but can only be raised when Python is configured with the
Éric Araujo713d3032010-11-18 16:38:46 +0000146 ``--with-fpectl`` option, or the :const:`WANT_SIGFPE_HANDLER` symbol is
Georg Brandl116aa622007-08-15 14:28:22 +0000147 defined in the :file:`pyconfig.h` file.
148
149
150.. exception:: GeneratorExit
151
Christian Heimescbf3b5c2007-12-03 21:02:03 +0000152 Raise when a :term:`generator`\'s :meth:`close` method is called. It
153 directly inherits from :exc:`BaseException` instead of :exc:`Exception` since
154 it is technically not an error.
Georg Brandl116aa622007-08-15 14:28:22 +0000155
Georg Brandl116aa622007-08-15 14:28:22 +0000156
Georg Brandl116aa622007-08-15 14:28:22 +0000157.. exception:: ImportError
158
159 Raised when an :keyword:`import` statement fails to find the module definition
160 or when a ``from ... import`` fails to find a name that is to be imported.
161
Brett Cannon79ec55e2012-04-12 20:24:54 -0400162 The :attr:`name` and :attr:`path` attributes can be set using keyword-only
163 arguments to the constructor. When set they represent the name of the module
164 that was attempted to be imported and the path to any file which triggered
165 the exception, respectively.
166
167 .. versionchanged:: 3.3
168 Added the :attr:`name` and :attr:`path` attributes.
169
Georg Brandl116aa622007-08-15 14:28:22 +0000170
171.. exception:: IndexError
172
Georg Brandl95817b32008-05-11 14:30:18 +0000173 Raised when a sequence subscript is out of range. (Slice indices are
174 silently truncated to fall in the allowed range; if an index is not an
175 integer, :exc:`TypeError` is raised.)
Georg Brandl116aa622007-08-15 14:28:22 +0000176
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000177 .. XXX xref to sequences
Georg Brandl116aa622007-08-15 14:28:22 +0000178
179
180.. exception:: KeyError
181
182 Raised when a mapping (dictionary) key is not found in the set of existing keys.
183
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000184 .. XXX xref to mapping objects?
Georg Brandl116aa622007-08-15 14:28:22 +0000185
186
187.. exception:: KeyboardInterrupt
188
189 Raised when the user hits the interrupt key (normally :kbd:`Control-C` or
Georg Brandl81ac1ce2007-08-31 17:17:17 +0000190 :kbd:`Delete`). During execution, a check for interrupts is made
191 regularly. The exception inherits from :exc:`BaseException` so as to not be
192 accidentally caught by code that catches :exc:`Exception` and thus prevent
193 the interpreter from exiting.
Georg Brandl116aa622007-08-15 14:28:22 +0000194
Georg Brandl116aa622007-08-15 14:28:22 +0000195
196.. exception:: MemoryError
197
198 Raised when an operation runs out of memory but the situation may still be
199 rescued (by deleting some objects). The associated value is a string indicating
200 what kind of (internal) operation ran out of memory. Note that because of the
Georg Brandl60203b42010-10-06 10:11:56 +0000201 underlying memory management architecture (C's :c:func:`malloc` function), the
Georg Brandl116aa622007-08-15 14:28:22 +0000202 interpreter may not always be able to completely recover from this situation; it
203 nevertheless raises an exception so that a stack traceback can be printed, in
204 case a run-away program was the cause.
205
206
207.. exception:: NameError
208
209 Raised when a local or global name is not found. This applies only to
210 unqualified names. The associated value is an error message that includes the
211 name that could not be found.
212
213
214.. exception:: NotImplementedError
215
216 This exception is derived from :exc:`RuntimeError`. In user defined base
217 classes, abstract methods should raise this exception when they require derived
218 classes to override the method.
219
Georg Brandl116aa622007-08-15 14:28:22 +0000220
221.. exception:: OSError
222
Christian Heimesa62da1d2008-01-12 19:39:10 +0000223 .. index:: module: errno
224
Antoine Pitrouf9c77462011-10-12 16:02:00 +0200225 This exception is raised when a system function returns a system-related
226 error, including I/O failures such as "file not found" or "disk full"
227 (not for illegal argument types or other incidental errors). Often a
228 subclass of :exc:`OSError` will actually be raised as described in
229 `OS exceptions`_ below. The :attr:`errno` attribute is a numeric error
230 code from the C variable :c:data:`errno`.
Christian Heimesa62da1d2008-01-12 19:39:10 +0000231
Antoine Pitrouf9c77462011-10-12 16:02:00 +0200232 Under Windows, the :attr:`winerror` attribute gives you the native
233 Windows error code. The :attr:`errno` attribute is then an approximate
234 translation, in POSIX terms, of that native error code.
235
236 Under all platforms, the :attr:`strerror` attribute is the corresponding
237 error message as provided by the operating system (as formatted by the C
238 functions :c:func:`perror` under POSIX, and :c:func:`FormatMessage`
239 Windows).
240
241 For exceptions that involve a file system path (such as :func:`open` or
242 :func:`os.unlink`), the exception instance will contain an additional
243 attribute, :attr:`filename`, which is the file name passed to the function.
Georg Brandl116aa622007-08-15 14:28:22 +0000244
Antoine Pitrou195e7022011-10-12 16:46:46 +0200245 .. versionchanged:: 3.3
246 :exc:`EnvironmentError`, :exc:`IOError`, :exc:`WindowsError`,
247 :exc:`VMSError`, :exc:`socket.error`, :exc:`select.error` and
248 :exc:`mmap.error` have been merged into :exc:`OSError`.
249
Georg Brandl116aa622007-08-15 14:28:22 +0000250
251.. exception:: OverflowError
252
253 Raised when the result of an arithmetic operation is too large to be
Georg Brandlba956ae2007-11-29 17:24:34 +0000254 represented. This cannot occur for integers (which would rather raise
Georg Brandl116aa622007-08-15 14:28:22 +0000255 :exc:`MemoryError` than give up). Because of the lack of standardization of
256 floating point exception handling in C, most floating point operations also
Georg Brandl81ac1ce2007-08-31 17:17:17 +0000257 aren't checked.
Georg Brandl116aa622007-08-15 14:28:22 +0000258
259
260.. exception:: ReferenceError
261
262 This exception is raised when a weak reference proxy, created by the
263 :func:`weakref.proxy` function, is used to access an attribute of the referent
264 after it has been garbage collected. For more information on weak references,
265 see the :mod:`weakref` module.
266
Georg Brandl116aa622007-08-15 14:28:22 +0000267
268.. exception:: RuntimeError
269
270 Raised when an error is detected that doesn't fall in any of the other
271 categories. The associated value is a string indicating what precisely went
272 wrong. (This exception is mostly a relic from a previous version of the
273 interpreter; it is not used very much any more.)
274
275
276.. exception:: StopIteration
277
Georg Brandlc4a55fc2010-02-06 18:46:57 +0000278 Raised by built-in function :func:`next` and an :term:`iterator`\'s
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000279 :meth:`__next__` method to signal that there are no further items to be
280 produced by the iterator.
281
282 The exception object has a single attribute :attr:`value`, which is
283 given as an argument when constructing the exception, and defaults
284 to :const:`None`.
285
286 When a generator function returns, a new :exc:`StopIteration` instance is
287 raised, and the value returned by the function is used as the
288 :attr:`value` parameter to the constructor of the exception.
Georg Brandl116aa622007-08-15 14:28:22 +0000289
Nick Coghlan0ed80192012-01-14 14:43:24 +1000290 .. versionchanged:: 3.3
291 Added ``value`` attribute and the ability for generator functions to
292 use it to return a value.
Georg Brandl116aa622007-08-15 14:28:22 +0000293
294.. exception:: SyntaxError
295
296 Raised when the parser encounters a syntax error. This may occur in an
297 :keyword:`import` statement, in a call to the built-in functions :func:`exec`
298 or :func:`eval`, or when reading the initial script or standard input
299 (also interactively).
300
Georg Brandl116aa622007-08-15 14:28:22 +0000301 Instances of this class have attributes :attr:`filename`, :attr:`lineno`,
302 :attr:`offset` and :attr:`text` for easier access to the details. :func:`str`
303 of the exception instance returns only the message.
304
305
Georg Brandl0bdfbfa2010-12-18 17:51:28 +0000306.. exception:: IndentationError
307
308 Base class for syntax errors related to incorrect indentation. This is a
309 subclass of :exc:`SyntaxError`.
310
311
312.. exception:: TabError
313
314 Raised when indentation contains an inconsistent use of tabs and spaces.
315 This is a subclass of :exc:`IndentationError`.
316
317
Georg Brandl116aa622007-08-15 14:28:22 +0000318.. exception:: SystemError
319
320 Raised when the interpreter finds an internal error, but the situation does not
321 look so serious to cause it to abandon all hope. The associated value is a
322 string indicating what went wrong (in low-level terms).
323
324 You should report this to the author or maintainer of your Python interpreter.
325 Be sure to report the version of the Python interpreter (``sys.version``; it is
326 also printed at the start of an interactive Python session), the exact error
327 message (the exception's associated value) and if possible the source of the
328 program that triggered the error.
329
330
331.. exception:: SystemExit
332
333 This exception is raised by the :func:`sys.exit` function. When it is not
334 handled, the Python interpreter exits; no stack traceback is printed. If the
Georg Brandl95817b32008-05-11 14:30:18 +0000335 associated value is an integer, it specifies the system exit status (passed
Georg Brandl60203b42010-10-06 10:11:56 +0000336 to C's :c:func:`exit` function); if it is ``None``, the exit status is zero;
Georg Brandl95817b32008-05-11 14:30:18 +0000337 if it has another type (such as a string), the object's value is printed and
338 the exit status is one.
Georg Brandl116aa622007-08-15 14:28:22 +0000339
Georg Brandl116aa622007-08-15 14:28:22 +0000340 Instances have an attribute :attr:`code` which is set to the proposed exit
341 status or error message (defaulting to ``None``). Also, this exception derives
342 directly from :exc:`BaseException` and not :exc:`Exception`, since it is not
343 technically an error.
344
345 A call to :func:`sys.exit` is translated into an exception so that clean-up
346 handlers (:keyword:`finally` clauses of :keyword:`try` statements) can be
347 executed, and so that a debugger can execute a script without running the risk
348 of losing control. The :func:`os._exit` function can be used if it is
349 absolutely positively necessary to exit immediately (for example, in the child
350 process after a call to :func:`fork`).
351
352 The exception inherits from :exc:`BaseException` instead of :exc:`Exception` so
353 that it is not accidentally caught by code that catches :exc:`Exception`. This
354 allows the exception to properly propagate up and cause the interpreter to exit.
355
Georg Brandl116aa622007-08-15 14:28:22 +0000356
357.. exception:: TypeError
358
359 Raised when an operation or function is applied to an object of inappropriate
360 type. The associated value is a string giving details about the type mismatch.
361
362
363.. exception:: UnboundLocalError
364
365 Raised when a reference is made to a local variable in a function or method, but
366 no value has been bound to that variable. This is a subclass of
367 :exc:`NameError`.
368
Georg Brandl116aa622007-08-15 14:28:22 +0000369
370.. exception:: UnicodeError
371
372 Raised when a Unicode-related encoding or decoding error occurs. It is a
373 subclass of :exc:`ValueError`.
374
Georg Brandl116aa622007-08-15 14:28:22 +0000375
376.. exception:: UnicodeEncodeError
377
378 Raised when a Unicode-related error occurs during encoding. It is a subclass of
379 :exc:`UnicodeError`.
380
Georg Brandl116aa622007-08-15 14:28:22 +0000381
382.. exception:: UnicodeDecodeError
383
384 Raised when a Unicode-related error occurs during decoding. It is a subclass of
385 :exc:`UnicodeError`.
386
Georg Brandl116aa622007-08-15 14:28:22 +0000387
388.. exception:: UnicodeTranslateError
389
390 Raised when a Unicode-related error occurs during translating. It is a subclass
391 of :exc:`UnicodeError`.
392
Georg Brandl116aa622007-08-15 14:28:22 +0000393
394.. exception:: ValueError
395
396 Raised when a built-in operation or function receives an argument that has the
397 right type but an inappropriate value, and the situation is not described by a
398 more precise exception such as :exc:`IndexError`.
399
400
Georg Brandl116aa622007-08-15 14:28:22 +0000401.. exception:: ZeroDivisionError
402
403 Raised when the second argument of a division or modulo operation is zero. The
404 associated value is a string indicating the type of the operands and the
405 operation.
406
Georg Brandlfbd1b222009-12-29 21:38:35 +0000407
Antoine Pitrouf9c77462011-10-12 16:02:00 +0200408The following exceptions are kept for compatibility with previous versions;
409starting from Python 3.3, they are aliases of :exc:`OSError`.
410
411.. exception:: EnvironmentError
412
413.. exception:: IOError
414
415.. exception:: VMSError
416
417 Only available on VMS.
418
419.. exception:: WindowsError
420
421 Only available on Windows.
422
423
424OS exceptions
425^^^^^^^^^^^^^
426
427The following exceptions are subclasses of :exc:`OSError`, they get raised
428depending on the system error code.
429
430.. exception:: BlockingIOError
431
432 Raised when an operation would block on an object (e.g. socket) set
433 for non-blocking operation.
434 Corresponds to :c:data:`errno` ``EAGAIN``, ``EALREADY``,
435 ``EWOULDBLOCK`` and ``EINPROGRESS``.
436
Antoine Pitrouf55011f2011-10-12 18:57:23 +0200437 In addition to those of :exc:`OSError`, :exc:`BlockingIOError` can have
438 one more attribute:
439
440 .. attribute:: characters_written
441
442 An integer containing the number of characters written to the stream
443 before it blocked. This attribute is available when using the
444 buffered I/O classes from the :mod:`io` module.
445
Antoine Pitrouf9c77462011-10-12 16:02:00 +0200446.. exception:: ChildProcessError
447
448 Raised when an operation on a child process failed.
449 Corresponds to :c:data:`errno` ``ECHILD``.
450
451.. exception:: ConnectionError
452
453 A base class for connection-related issues. Subclasses are
454 :exc:`BrokenPipeError`, :exc:`ConnectionAbortedError`,
455 :exc:`ConnectionRefusedError` and :exc:`ConnectionResetError`.
456
457 .. exception:: BrokenPipeError
458
459 A subclass of :exc:`ConnectionError`, raised when trying to write on a
460 pipe while the other end has been closed, or trying to write on a socket
461 which has been shutdown for writing.
462 Corresponds to :c:data:`errno` ``EPIPE`` and ``ESHUTDOWN``.
463
464 .. exception:: ConnectionAbortedError
465
466 A subclass of :exc:`ConnectionError`, raised when a connection attempt
467 is aborted by the peer.
468 Corresponds to :c:data:`errno` ``ECONNABORTED``.
469
470 .. exception:: ConnectionRefusedError
471
472 A subclass of :exc:`ConnectionError`, raised when a connection attempt
473 is refused by the peer.
474 Corresponds to :c:data:`errno` ``ECONNREFUSED``.
475
476 .. exception:: ConnectionResetError
477
478 A subclass of :exc:`ConnectionError`, raised when a connection is
479 reset by the peer.
480 Corresponds to :c:data:`errno` ``ECONNRESET``.
481
482.. exception:: FileExistsError
483
484 Raised when trying to create a file or directory which already exists.
485 Corresponds to :c:data:`errno` ``EEXIST``.
486
487.. exception:: FileNotFoundError
488
489 Raised when a file or directory is requested but doesn't exist.
490 Corresponds to :c:data:`errno` ``ENOENT``.
491
492.. exception:: InterruptedError
493
494 Raised when a system call is interrupted by an incoming signal.
495 Corresponds to :c:data:`errno` ``EEINTR``.
496
497.. exception:: IsADirectoryError
498
499 Raised when a file operation (such as :func:`os.remove`) is requested
500 on a directory.
501 Corresponds to :c:data:`errno` ``EISDIR``.
502
503.. exception:: NotADirectoryError
504
505 Raised when a directory operation (such as :func:`os.listdir`) is requested
506 on something which is not a directory.
507 Corresponds to :c:data:`errno` ``ENOTDIR``.
508
509.. exception:: PermissionError
510
511 Raised when trying to run an operation without the adequate access
512 rights - for example filesystem permissions.
513 Corresponds to :c:data:`errno` ``EACCES`` and ``EPERM``.
514
515.. exception:: ProcessLookupError
516
517 Raised when a given process doesn't exist.
518 Corresponds to :c:data:`errno` ``ESRCH``.
519
520.. exception:: TimeoutError
521
522 Raised when a system function timed out at the system level.
523 Corresponds to :c:data:`errno` ``ETIMEDOUT``.
524
525.. versionadded:: 3.3
526 All the above :exc:`OSError` subclasses were added.
527
528
529.. seealso::
530
531 :pep:`3151` - Reworking the OS and IO exception hierarchy
532 PEP written and implemented by Antoine Pitrou.
533
534
535Warnings
536--------
537
Georg Brandl116aa622007-08-15 14:28:22 +0000538The following exceptions are used as warning categories; see the :mod:`warnings`
539module for more information.
540
Georg Brandl116aa622007-08-15 14:28:22 +0000541.. exception:: Warning
542
543 Base class for warning categories.
544
545
546.. exception:: UserWarning
547
548 Base class for warnings generated by user code.
549
550
551.. exception:: DeprecationWarning
552
553 Base class for warnings about deprecated features.
554
555
556.. exception:: PendingDeprecationWarning
557
558 Base class for warnings about features which will be deprecated in the future.
559
560
561.. exception:: SyntaxWarning
562
563 Base class for warnings about dubious syntax
564
565
566.. exception:: RuntimeWarning
567
568 Base class for warnings about dubious runtime behavior.
569
570
571.. exception:: FutureWarning
572
573 Base class for warnings about constructs that will change semantically in the
574 future.
575
576
577.. exception:: ImportWarning
578
579 Base class for warnings about probable mistakes in module imports.
580
Georg Brandl116aa622007-08-15 14:28:22 +0000581
582.. exception:: UnicodeWarning
583
584 Base class for warnings related to Unicode.
585
Georg Brandl08be72d2010-10-24 15:11:22 +0000586
Guido van Rossum98297ee2007-11-06 21:34:58 +0000587.. exception:: BytesWarning
Georg Brandl116aa622007-08-15 14:28:22 +0000588
Guido van Rossum98297ee2007-11-06 21:34:58 +0000589 Base class for warnings related to :class:`bytes` and :class:`buffer`.
590
Georg Brandl08be72d2010-10-24 15:11:22 +0000591
592.. exception:: ResourceWarning
593
594 Base class for warnings related to resource usage.
595
596 .. versionadded:: 3.2
597
598
599
Alexandre Vassalottic22c6f22009-07-21 00:51:58 +0000600Exception hierarchy
601-------------------
Guido van Rossum98297ee2007-11-06 21:34:58 +0000602
603The class hierarchy for built-in exceptions is:
Georg Brandl116aa622007-08-15 14:28:22 +0000604
605.. literalinclude:: ../../Lib/test/exception_hierarchy.txt