blob: faf6732a4178b104886ae7f2cb017f0af5323714 [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
Benjamin Petersond5a1c442012-05-14 22:09:31 -070042This implicit exception chain can be made explicit by using :keyword:`from` with
43:keyword:`raise`. The single argument to :keyword:`from` must be an exception
44or ``None``. It will be set as :attr:`__cause__` on the raised exception.
45Setting :attr:`__cause__` implicitly sets the :attr:`__suppress_context__` to
46``True``. If :attr:`__cause__` is an exception, it will be displayed. If
47:attr:`__cause__` is present or :attr:`__suppress_context__` has a true value,
48:attr:`__context__` will not be displayed.
Nick Coghlanab7bf212012-02-26 17:49:52 +100049
Benjamin Petersond5a1c442012-05-14 22:09:31 -070050In either case, the default exception handling code will not display any of the
51remaining links in the :attr:`__context__` chain if :attr:`__cause__` has been
52set.
Nick Coghlanab7bf212012-02-26 17:49:52 +100053
Antoine Pitrouf9c77462011-10-12 16:02:00 +020054
55Base classes
56------------
57
Georg Brandlfbd1b222009-12-29 21:38:35 +000058The following exceptions are used mostly as base classes for other exceptions.
Georg Brandl116aa622007-08-15 14:28:22 +000059
Georg Brandl116aa622007-08-15 14:28:22 +000060.. exception:: BaseException
61
62 The base class for all built-in exceptions. It is not meant to be directly
Georg Brandlfb6fd5d2011-01-07 18:28:45 +000063 inherited by user-defined classes (for that, use :exc:`Exception`). If
Amaury Forgeot d'Arc3b1acf12011-11-22 19:34:08 +010064 :func:`str` is called on an instance of this class, the representation of
65 the argument(s) to the instance are returned, or the empty string when
66 there were no arguments.
Georg Brandlfb6fd5d2011-01-07 18:28:45 +000067
68 .. attribute:: args
69
70 The tuple of arguments given to the exception constructor. Some built-in
71 exceptions (like :exc:`IOError`) expect a certain number of arguments and
72 assign a special meaning to the elements of this tuple, while others are
73 usually called only with a single string giving an error message.
74
75 .. method:: with_traceback(tb)
76
77 This method sets *tb* as the new traceback for the exception and returns
78 the exception object. It is usually used in exception handling code like
79 this::
80
81 try:
82 ...
83 except SomeException:
84 tb = sys.exc_info()[2]
85 raise OtherException(...).with_traceback(tb)
Georg Brandl116aa622007-08-15 14:28:22 +000086
Georg Brandl116aa622007-08-15 14:28:22 +000087
88.. exception:: Exception
89
90 All built-in, non-system-exiting exceptions are derived from this class. All
91 user-defined exceptions should also be derived from this class.
92
Georg Brandl116aa622007-08-15 14:28:22 +000093
94.. exception:: ArithmeticError
95
96 The base class for those built-in exceptions that are raised for various
97 arithmetic errors: :exc:`OverflowError`, :exc:`ZeroDivisionError`,
98 :exc:`FloatingPointError`.
99
100
Georg Brandl0bdfbfa2010-12-18 17:51:28 +0000101.. exception:: BufferError
102
103 Raised when a :ref:`buffer <bufferobjects>` related operation cannot be
104 performed.
105
106
Georg Brandl116aa622007-08-15 14:28:22 +0000107.. exception:: LookupError
108
Benjamin Petersonfa0d7032009-06-01 22:42:33 +0000109 The base class for the exceptions that are raised when a key or index used on
110 a mapping or sequence is invalid: :exc:`IndexError`, :exc:`KeyError`. This
111 can be raised directly by :func:`codecs.lookup`.
Georg Brandl116aa622007-08-15 14:28:22 +0000112
113
Antoine Pitrouf9c77462011-10-12 16:02:00 +0200114Concrete exceptions
115-------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000116
Georg Brandlfbd1b222009-12-29 21:38:35 +0000117The following exceptions are the exceptions that are usually raised.
Georg Brandl116aa622007-08-15 14:28:22 +0000118
119.. exception:: AssertionError
120
121 .. index:: statement: assert
122
123 Raised when an :keyword:`assert` statement fails.
124
125
126.. exception:: AttributeError
127
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000128 Raised when an attribute reference (see :ref:`attribute-references`) or
129 assignment fails. (When an object does not support attribute references or
130 attribute assignments at all, :exc:`TypeError` is raised.)
Georg Brandl116aa622007-08-15 14:28:22 +0000131
132
133.. exception:: EOFError
134
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000135 Raised when one of the built-in functions (:func:`input` or :func:`raw_input`)
136 hits an end-of-file condition (EOF) without reading any data. (N.B.: the
Georg Brandl81ac1ce2007-08-31 17:17:17 +0000137 :meth:`file.read` and :meth:`file.readline` methods return an empty string
138 when they hit EOF.)
Georg Brandl116aa622007-08-15 14:28:22 +0000139
140
141.. exception:: FloatingPointError
142
143 Raised when a floating point operation fails. This exception is always defined,
144 but can only be raised when Python is configured with the
Éric Araujo713d3032010-11-18 16:38:46 +0000145 ``--with-fpectl`` option, or the :const:`WANT_SIGFPE_HANDLER` symbol is
Georg Brandl116aa622007-08-15 14:28:22 +0000146 defined in the :file:`pyconfig.h` file.
147
148
149.. exception:: GeneratorExit
150
Christian Heimescbf3b5c2007-12-03 21:02:03 +0000151 Raise when a :term:`generator`\'s :meth:`close` method is called. It
152 directly inherits from :exc:`BaseException` instead of :exc:`Exception` since
153 it is technically not an error.
Georg Brandl116aa622007-08-15 14:28:22 +0000154
Georg Brandl116aa622007-08-15 14:28:22 +0000155
Georg Brandl116aa622007-08-15 14:28:22 +0000156.. exception:: ImportError
157
158 Raised when an :keyword:`import` statement fails to find the module definition
159 or when a ``from ... import`` fails to find a name that is to be imported.
160
Brett Cannon79ec55e2012-04-12 20:24:54 -0400161 The :attr:`name` and :attr:`path` attributes can be set using keyword-only
162 arguments to the constructor. When set they represent the name of the module
163 that was attempted to be imported and the path to any file which triggered
164 the exception, respectively.
165
166 .. versionchanged:: 3.3
167 Added the :attr:`name` and :attr:`path` attributes.
168
Georg Brandl116aa622007-08-15 14:28:22 +0000169
170.. exception:: IndexError
171
Georg Brandl95817b32008-05-11 14:30:18 +0000172 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 an
174 integer, :exc:`TypeError` is raised.)
Georg Brandl116aa622007-08-15 14:28:22 +0000175
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000176 .. XXX xref to sequences
Georg Brandl116aa622007-08-15 14:28:22 +0000177
178
179.. exception:: KeyError
180
181 Raised when a mapping (dictionary) key is not found in the set of existing keys.
182
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000183 .. XXX xref to mapping objects?
Georg Brandl116aa622007-08-15 14:28:22 +0000184
185
186.. exception:: KeyboardInterrupt
187
188 Raised when the user hits the interrupt key (normally :kbd:`Control-C` or
Georg Brandl81ac1ce2007-08-31 17:17:17 +0000189 :kbd:`Delete`). During execution, a check for interrupts is made
190 regularly. The exception inherits from :exc:`BaseException` so as to not be
191 accidentally caught by code that catches :exc:`Exception` and thus prevent
192 the interpreter from exiting.
Georg Brandl116aa622007-08-15 14:28:22 +0000193
Georg Brandl116aa622007-08-15 14:28:22 +0000194
195.. exception:: MemoryError
196
197 Raised when an operation runs out of memory but the situation may still be
198 rescued (by deleting some objects). The associated value is a string indicating
199 what kind of (internal) operation ran out of memory. Note that because of the
Georg Brandl60203b42010-10-06 10:11:56 +0000200 underlying memory management architecture (C's :c:func:`malloc` function), the
Georg Brandl116aa622007-08-15 14:28:22 +0000201 interpreter may not always be able to completely recover from this situation; it
202 nevertheless raises an exception so that a stack traceback can be printed, in
203 case a run-away program was the cause.
204
205
206.. exception:: NameError
207
208 Raised when a local or global name is not found. This applies only to
209 unqualified names. The associated value is an error message that includes the
210 name that could not be found.
211
212
213.. exception:: NotImplementedError
214
215 This exception is derived from :exc:`RuntimeError`. In user defined base
216 classes, abstract methods should raise this exception when they require derived
217 classes to override the method.
218
Georg Brandl116aa622007-08-15 14:28:22 +0000219
220.. exception:: OSError
221
Christian Heimesa62da1d2008-01-12 19:39:10 +0000222 .. index:: module: errno
223
Antoine Pitrouf9c77462011-10-12 16:02:00 +0200224 This exception is raised when a system function returns a system-related
225 error, including I/O failures such as "file not found" or "disk full"
226 (not for illegal argument types or other incidental errors). Often a
227 subclass of :exc:`OSError` will actually be raised as described in
228 `OS exceptions`_ below. The :attr:`errno` attribute is a numeric error
229 code from the C variable :c:data:`errno`.
Christian Heimesa62da1d2008-01-12 19:39:10 +0000230
Antoine Pitrouf9c77462011-10-12 16:02:00 +0200231 Under Windows, the :attr:`winerror` attribute gives you the native
232 Windows error code. The :attr:`errno` attribute is then an approximate
233 translation, in POSIX terms, of that native error code.
234
235 Under all platforms, the :attr:`strerror` attribute is the corresponding
236 error message as provided by the operating system (as formatted by the C
237 functions :c:func:`perror` under POSIX, and :c:func:`FormatMessage`
238 Windows).
239
240 For exceptions that involve a file system path (such as :func:`open` or
241 :func:`os.unlink`), the exception instance will contain an additional
242 attribute, :attr:`filename`, which is the file name passed to the function.
Georg Brandl116aa622007-08-15 14:28:22 +0000243
Antoine Pitrou195e7022011-10-12 16:46:46 +0200244 .. versionchanged:: 3.3
245 :exc:`EnvironmentError`, :exc:`IOError`, :exc:`WindowsError`,
246 :exc:`VMSError`, :exc:`socket.error`, :exc:`select.error` and
247 :exc:`mmap.error` have been merged into :exc:`OSError`.
248
Georg Brandl116aa622007-08-15 14:28:22 +0000249
250.. exception:: OverflowError
251
252 Raised when the result of an arithmetic operation is too large to be
Georg Brandlba956ae2007-11-29 17:24:34 +0000253 represented. This cannot occur for integers (which would rather raise
Georg Brandl116aa622007-08-15 14:28:22 +0000254 :exc:`MemoryError` than give up). Because of the lack of standardization of
255 floating point exception handling in C, most floating point operations also
Georg Brandl81ac1ce2007-08-31 17:17:17 +0000256 aren't checked.
Georg Brandl116aa622007-08-15 14:28:22 +0000257
258
259.. exception:: ReferenceError
260
261 This exception is raised when a weak reference proxy, created by the
262 :func:`weakref.proxy` function, is used to access an attribute of the referent
263 after it has been garbage collected. For more information on weak references,
264 see the :mod:`weakref` module.
265
Georg Brandl116aa622007-08-15 14:28:22 +0000266
267.. exception:: RuntimeError
268
269 Raised when an error is detected that doesn't fall in any of the other
270 categories. The associated value is a string indicating what precisely went
271 wrong. (This exception is mostly a relic from a previous version of the
272 interpreter; it is not used very much any more.)
273
274
275.. exception:: StopIteration
276
Georg Brandlc4a55fc2010-02-06 18:46:57 +0000277 Raised by built-in function :func:`next` and an :term:`iterator`\'s
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000278 :meth:`__next__` method to signal that there are no further items to be
279 produced by the iterator.
280
281 The exception object has a single attribute :attr:`value`, which is
282 given as an argument when constructing the exception, and defaults
283 to :const:`None`.
284
285 When a generator function returns, a new :exc:`StopIteration` instance is
286 raised, and the value returned by the function is used as the
287 :attr:`value` parameter to the constructor of the exception.
Georg Brandl116aa622007-08-15 14:28:22 +0000288
Nick Coghlan0ed80192012-01-14 14:43:24 +1000289 .. versionchanged:: 3.3
290 Added ``value`` attribute and the ability for generator functions to
291 use it to return a value.
Georg Brandl116aa622007-08-15 14:28:22 +0000292
293.. exception:: SyntaxError
294
295 Raised when the parser encounters a syntax error. This may occur in an
296 :keyword:`import` statement, in a call to the built-in functions :func:`exec`
297 or :func:`eval`, or when reading the initial script or standard input
298 (also interactively).
299
Georg Brandl116aa622007-08-15 14:28:22 +0000300 Instances of this class have attributes :attr:`filename`, :attr:`lineno`,
301 :attr:`offset` and :attr:`text` for easier access to the details. :func:`str`
302 of the exception instance returns only the message.
303
304
Georg Brandl0bdfbfa2010-12-18 17:51:28 +0000305.. exception:: IndentationError
306
307 Base class for syntax errors related to incorrect indentation. This is a
308 subclass of :exc:`SyntaxError`.
309
310
311.. exception:: TabError
312
313 Raised when indentation contains an inconsistent use of tabs and spaces.
314 This is a subclass of :exc:`IndentationError`.
315
316
Georg Brandl116aa622007-08-15 14:28:22 +0000317.. exception:: SystemError
318
319 Raised when the interpreter finds an internal error, but the situation does not
320 look so serious to cause it to abandon all hope. The associated value is a
321 string indicating what went wrong (in low-level terms).
322
323 You should report this to the author or maintainer of your Python interpreter.
324 Be sure to report the version of the Python interpreter (``sys.version``; it is
325 also printed at the start of an interactive Python session), the exact error
326 message (the exception's associated value) and if possible the source of the
327 program that triggered the error.
328
329
330.. exception:: SystemExit
331
332 This exception is raised by the :func:`sys.exit` function. When it is not
333 handled, the Python interpreter exits; no stack traceback is printed. If the
Georg Brandl95817b32008-05-11 14:30:18 +0000334 associated value is an integer, it specifies the system exit status (passed
Georg Brandl60203b42010-10-06 10:11:56 +0000335 to C's :c:func:`exit` function); if it is ``None``, the exit status is zero;
Georg Brandl95817b32008-05-11 14:30:18 +0000336 if it has another type (such as a string), the object's value is printed and
337 the exit status is one.
Georg Brandl116aa622007-08-15 14:28:22 +0000338
Georg Brandl116aa622007-08-15 14:28:22 +0000339 Instances have an attribute :attr:`code` which is set to the proposed exit
340 status or error message (defaulting to ``None``). Also, this exception derives
341 directly from :exc:`BaseException` and not :exc:`Exception`, since it is not
342 technically an error.
343
344 A call to :func:`sys.exit` is translated into an exception so that clean-up
345 handlers (:keyword:`finally` clauses of :keyword:`try` statements) can be
346 executed, and so that a debugger can execute a script without running the risk
347 of losing control. The :func:`os._exit` function can be used if it is
348 absolutely positively necessary to exit immediately (for example, in the child
349 process after a call to :func:`fork`).
350
351 The exception inherits from :exc:`BaseException` instead of :exc:`Exception` so
352 that it is not accidentally caught by code that catches :exc:`Exception`. This
353 allows the exception to properly propagate up and cause the interpreter to exit.
354
Georg Brandl116aa622007-08-15 14:28:22 +0000355
356.. exception:: TypeError
357
358 Raised when an operation or function is applied to an object of inappropriate
359 type. The associated value is a string giving details about the type mismatch.
360
361
362.. exception:: UnboundLocalError
363
364 Raised when a reference is made to a local variable in a function or method, but
365 no value has been bound to that variable. This is a subclass of
366 :exc:`NameError`.
367
Georg Brandl116aa622007-08-15 14:28:22 +0000368
369.. exception:: UnicodeError
370
371 Raised when a Unicode-related encoding or decoding error occurs. It is a
372 subclass of :exc:`ValueError`.
373
Georg Brandl116aa622007-08-15 14:28:22 +0000374
375.. exception:: UnicodeEncodeError
376
377 Raised when a Unicode-related error occurs during encoding. It is a subclass of
378 :exc:`UnicodeError`.
379
Georg Brandl116aa622007-08-15 14:28:22 +0000380
381.. exception:: UnicodeDecodeError
382
383 Raised when a Unicode-related error occurs during decoding. It is a subclass of
384 :exc:`UnicodeError`.
385
Georg Brandl116aa622007-08-15 14:28:22 +0000386
387.. exception:: UnicodeTranslateError
388
389 Raised when a Unicode-related error occurs during translating. It is a subclass
390 of :exc:`UnicodeError`.
391
Georg Brandl116aa622007-08-15 14:28:22 +0000392
393.. exception:: ValueError
394
395 Raised when a built-in operation or function receives an argument that has the
396 right type but an inappropriate value, and the situation is not described by a
397 more precise exception such as :exc:`IndexError`.
398
399
Georg Brandl116aa622007-08-15 14:28:22 +0000400.. exception:: ZeroDivisionError
401
402 Raised when the second argument of a division or modulo operation is zero. The
403 associated value is a string indicating the type of the operands and the
404 operation.
405
Georg Brandlfbd1b222009-12-29 21:38:35 +0000406
Antoine Pitrouf9c77462011-10-12 16:02:00 +0200407The following exceptions are kept for compatibility with previous versions;
408starting from Python 3.3, they are aliases of :exc:`OSError`.
409
410.. exception:: EnvironmentError
411
412.. exception:: IOError
413
414.. exception:: VMSError
415
416 Only available on VMS.
417
418.. exception:: WindowsError
419
420 Only available on Windows.
421
422
423OS exceptions
424^^^^^^^^^^^^^
425
426The following exceptions are subclasses of :exc:`OSError`, they get raised
427depending on the system error code.
428
429.. exception:: BlockingIOError
430
431 Raised when an operation would block on an object (e.g. socket) set
432 for non-blocking operation.
433 Corresponds to :c:data:`errno` ``EAGAIN``, ``EALREADY``,
434 ``EWOULDBLOCK`` and ``EINPROGRESS``.
435
Antoine Pitrouf55011f2011-10-12 18:57:23 +0200436 In addition to those of :exc:`OSError`, :exc:`BlockingIOError` can have
437 one more attribute:
438
439 .. attribute:: characters_written
440
441 An integer containing the number of characters written to the stream
442 before it blocked. This attribute is available when using the
443 buffered I/O classes from the :mod:`io` module.
444
Antoine Pitrouf9c77462011-10-12 16:02:00 +0200445.. exception:: ChildProcessError
446
447 Raised when an operation on a child process failed.
448 Corresponds to :c:data:`errno` ``ECHILD``.
449
450.. exception:: ConnectionError
451
452 A base class for connection-related issues. Subclasses are
453 :exc:`BrokenPipeError`, :exc:`ConnectionAbortedError`,
454 :exc:`ConnectionRefusedError` and :exc:`ConnectionResetError`.
455
456 .. exception:: BrokenPipeError
457
458 A subclass of :exc:`ConnectionError`, raised when trying to write on a
459 pipe while the other end has been closed, or trying to write on a socket
460 which has been shutdown for writing.
461 Corresponds to :c:data:`errno` ``EPIPE`` and ``ESHUTDOWN``.
462
463 .. exception:: ConnectionAbortedError
464
465 A subclass of :exc:`ConnectionError`, raised when a connection attempt
466 is aborted by the peer.
467 Corresponds to :c:data:`errno` ``ECONNABORTED``.
468
469 .. exception:: ConnectionRefusedError
470
471 A subclass of :exc:`ConnectionError`, raised when a connection attempt
472 is refused by the peer.
473 Corresponds to :c:data:`errno` ``ECONNREFUSED``.
474
475 .. exception:: ConnectionResetError
476
477 A subclass of :exc:`ConnectionError`, raised when a connection is
478 reset by the peer.
479 Corresponds to :c:data:`errno` ``ECONNRESET``.
480
481.. exception:: FileExistsError
482
483 Raised when trying to create a file or directory which already exists.
484 Corresponds to :c:data:`errno` ``EEXIST``.
485
486.. exception:: FileNotFoundError
487
488 Raised when a file or directory is requested but doesn't exist.
489 Corresponds to :c:data:`errno` ``ENOENT``.
490
491.. exception:: InterruptedError
492
493 Raised when a system call is interrupted by an incoming signal.
494 Corresponds to :c:data:`errno` ``EEINTR``.
495
496.. exception:: IsADirectoryError
497
498 Raised when a file operation (such as :func:`os.remove`) is requested
499 on a directory.
500 Corresponds to :c:data:`errno` ``EISDIR``.
501
502.. exception:: NotADirectoryError
503
504 Raised when a directory operation (such as :func:`os.listdir`) is requested
505 on something which is not a directory.
506 Corresponds to :c:data:`errno` ``ENOTDIR``.
507
508.. exception:: PermissionError
509
510 Raised when trying to run an operation without the adequate access
511 rights - for example filesystem permissions.
512 Corresponds to :c:data:`errno` ``EACCES`` and ``EPERM``.
513
514.. exception:: ProcessLookupError
515
516 Raised when a given process doesn't exist.
517 Corresponds to :c:data:`errno` ``ESRCH``.
518
519.. exception:: TimeoutError
520
521 Raised when a system function timed out at the system level.
522 Corresponds to :c:data:`errno` ``ETIMEDOUT``.
523
524.. versionadded:: 3.3
525 All the above :exc:`OSError` subclasses were added.
526
527
528.. seealso::
529
530 :pep:`3151` - Reworking the OS and IO exception hierarchy
531 PEP written and implemented by Antoine Pitrou.
532
533
534Warnings
535--------
536
Georg Brandl116aa622007-08-15 14:28:22 +0000537The following exceptions are used as warning categories; see the :mod:`warnings`
538module for more information.
539
Georg Brandl116aa622007-08-15 14:28:22 +0000540.. exception:: Warning
541
542 Base class for warning categories.
543
544
545.. exception:: UserWarning
546
547 Base class for warnings generated by user code.
548
549
550.. exception:: DeprecationWarning
551
552 Base class for warnings about deprecated features.
553
554
555.. exception:: PendingDeprecationWarning
556
557 Base class for warnings about features which will be deprecated in the future.
558
559
560.. exception:: SyntaxWarning
561
562 Base class for warnings about dubious syntax
563
564
565.. exception:: RuntimeWarning
566
567 Base class for warnings about dubious runtime behavior.
568
569
570.. exception:: FutureWarning
571
572 Base class for warnings about constructs that will change semantically in the
573 future.
574
575
576.. exception:: ImportWarning
577
578 Base class for warnings about probable mistakes in module imports.
579
Georg Brandl116aa622007-08-15 14:28:22 +0000580
581.. exception:: UnicodeWarning
582
583 Base class for warnings related to Unicode.
584
Georg Brandl08be72d2010-10-24 15:11:22 +0000585
Guido van Rossum98297ee2007-11-06 21:34:58 +0000586.. exception:: BytesWarning
Georg Brandl116aa622007-08-15 14:28:22 +0000587
Guido van Rossum98297ee2007-11-06 21:34:58 +0000588 Base class for warnings related to :class:`bytes` and :class:`buffer`.
589
Georg Brandl08be72d2010-10-24 15:11:22 +0000590
591.. exception:: ResourceWarning
592
593 Base class for warnings related to resource usage.
594
595 .. versionadded:: 3.2
596
597
598
Alexandre Vassalottic22c6f22009-07-21 00:51:58 +0000599Exception hierarchy
600-------------------
Guido van Rossum98297ee2007-11-06 21:34:58 +0000601
602The class hierarchy for built-in exceptions is:
Georg Brandl116aa622007-08-15 14:28:22 +0000603
604.. literalinclude:: ../../Lib/test/exception_hierarchy.txt