Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | .. _bltin-exceptions: |
| 2 | |
| 3 | Built-in Exceptions |
| 4 | =================== |
| 5 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 6 | .. index:: |
| 7 | statement: try |
| 8 | statement: except |
| 9 | |
Georg Brandl | fbd1b22 | 2009-12-29 21:38:35 +0000 | [diff] [blame] | 10 | In 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 Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 12 | clause that mentions a particular class, that clause also handles any exception |
| 13 | classes derived from that class (but not exception classes from which *it* is |
| 14 | derived). Two exception classes that are not related via subclassing are never |
| 15 | equivalent, even if they have the same name. |
| 16 | |
| 17 | .. index:: statement: raise |
| 18 | |
| 19 | The built-in exceptions listed below can be generated by the interpreter or |
| 20 | built-in functions. Except where mentioned, they have an "associated value" |
Georg Brandl | fb6fd5d | 2011-01-07 18:28:45 +0000 | [diff] [blame] | 21 | indicating the detailed cause of the error. This may be a string or a tuple of |
| 22 | several items of information (e.g., an error code and a string explaining the |
| 23 | code). The associated value is usually passed as arguments to the exception |
| 24 | class's constructor. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 25 | |
| 26 | User code can raise built-in exceptions. This can be used to test an exception |
| 27 | handler or to report an error condition "just like" the situation in which the |
| 28 | interpreter raises the same exception; but beware that there is nothing to |
| 29 | prevent user code from raising an inappropriate error. |
| 30 | |
Mark Dickinson | abf079d | 2014-04-14 11:20:12 -0400 | [diff] [blame] | 31 | The built-in exception classes can be subclassed to define new exceptions; |
| 32 | programmers are encouraged to derive new exceptions from the :exc:`Exception` |
| 33 | class or one of its subclasses, and not from :exc:`BaseException`. More |
| 34 | information on defining exceptions is available in the Python Tutorial under |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 35 | :ref:`tut-userexceptions`. |
| 36 | |
Georg Brandl | e4196d3 | 2014-10-31 09:41:46 +0100 | [diff] [blame] | 37 | When raising (or re-raising) an exception in an :keyword:`except` or |
| 38 | :keyword:`finally` clause |
Nick Coghlan | ab7bf21 | 2012-02-26 17:49:52 +1000 | [diff] [blame] | 39 | :attr:`__context__` is automatically set to the last exception caught; if the |
| 40 | new exception is not handled the traceback that is eventually displayed will |
| 41 | include the originating exception(s) and the final exception. |
| 42 | |
Nick Coghlan | 0eee97c | 2012-12-09 16:21:46 +1000 | [diff] [blame] | 43 | When raising a new exception (rather than using a bare ``raise`` to re-raise |
| 44 | the exception currently being handled), the implicit exception context can be |
| 45 | supplemented with an explicit cause by using :keyword:`from` with |
| 46 | :keyword:`raise`:: |
| 47 | |
| 48 | raise new_exc from original_exc |
| 49 | |
| 50 | The expression following :keyword:`from` must be an exception or ``None``. It |
| 51 | will be set as :attr:`__cause__` on the raised exception. Setting |
| 52 | :attr:`__cause__` also implicitly sets the :attr:`__suppress_context__` |
| 53 | attribute to ``True``, so that using ``raise new_exc from None`` |
| 54 | effectively replaces the old exception with the new one for display |
| 55 | purposes (e.g. converting :exc:`KeyError` to :exc:`AttributeError`, while |
| 56 | leaving the old exception available in :attr:`__context__` for introspection |
| 57 | when debugging. |
Nick Coghlan | ab7bf21 | 2012-02-26 17:49:52 +1000 | [diff] [blame] | 58 | |
Nick Coghlan | 8e18fc8 | 2012-12-08 21:39:24 +1000 | [diff] [blame] | 59 | The default traceback display code shows these chained exceptions in |
| 60 | addition to the traceback for the exception itself. An explicitly chained |
| 61 | exception in :attr:`__cause__` is always shown when present. An implicitly |
| 62 | chained exception in :attr:`__context__` is shown only if :attr:`__cause__` |
Nick Coghlan | 0eee97c | 2012-12-09 16:21:46 +1000 | [diff] [blame] | 63 | is :const:`None` and :attr:`__suppress_context__` is false. |
Nick Coghlan | 8e18fc8 | 2012-12-08 21:39:24 +1000 | [diff] [blame] | 64 | |
| 65 | In either case, the exception itself is always shown after any chained |
| 66 | exceptions so that the final line of the traceback always shows the last |
| 67 | exception that was raised. |
Nick Coghlan | ab7bf21 | 2012-02-26 17:49:52 +1000 | [diff] [blame] | 68 | |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 69 | |
| 70 | Base classes |
| 71 | ------------ |
| 72 | |
Georg Brandl | fbd1b22 | 2009-12-29 21:38:35 +0000 | [diff] [blame] | 73 | The following exceptions are used mostly as base classes for other exceptions. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 74 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 75 | .. exception:: BaseException |
| 76 | |
| 77 | The base class for all built-in exceptions. It is not meant to be directly |
Georg Brandl | fb6fd5d | 2011-01-07 18:28:45 +0000 | [diff] [blame] | 78 | inherited by user-defined classes (for that, use :exc:`Exception`). If |
Amaury Forgeot d'Arc | 3b1acf1 | 2011-11-22 19:34:08 +0100 | [diff] [blame] | 79 | :func:`str` is called on an instance of this class, the representation of |
| 80 | the argument(s) to the instance are returned, or the empty string when |
| 81 | there were no arguments. |
Georg Brandl | fb6fd5d | 2011-01-07 18:28:45 +0000 | [diff] [blame] | 82 | |
| 83 | .. attribute:: args |
| 84 | |
| 85 | The tuple of arguments given to the exception constructor. Some built-in |
Andrew Svetlov | 5898d4f | 2014-04-01 00:44:13 +0300 | [diff] [blame] | 86 | exceptions (like :exc:`OSError`) expect a certain number of arguments and |
Georg Brandl | fb6fd5d | 2011-01-07 18:28:45 +0000 | [diff] [blame] | 87 | assign a special meaning to the elements of this tuple, while others are |
| 88 | usually called only with a single string giving an error message. |
| 89 | |
| 90 | .. method:: with_traceback(tb) |
| 91 | |
| 92 | This method sets *tb* as the new traceback for the exception and returns |
| 93 | the exception object. It is usually used in exception handling code like |
| 94 | this:: |
| 95 | |
| 96 | try: |
| 97 | ... |
| 98 | except SomeException: |
| 99 | tb = sys.exc_info()[2] |
| 100 | raise OtherException(...).with_traceback(tb) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 101 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 102 | |
| 103 | .. exception:: Exception |
| 104 | |
| 105 | All built-in, non-system-exiting exceptions are derived from this class. All |
| 106 | user-defined exceptions should also be derived from this class. |
| 107 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 108 | |
| 109 | .. exception:: ArithmeticError |
| 110 | |
| 111 | The base class for those built-in exceptions that are raised for various |
| 112 | arithmetic errors: :exc:`OverflowError`, :exc:`ZeroDivisionError`, |
| 113 | :exc:`FloatingPointError`. |
| 114 | |
| 115 | |
Georg Brandl | 0bdfbfa | 2010-12-18 17:51:28 +0000 | [diff] [blame] | 116 | .. exception:: BufferError |
| 117 | |
| 118 | Raised when a :ref:`buffer <bufferobjects>` related operation cannot be |
| 119 | performed. |
| 120 | |
| 121 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 122 | .. exception:: LookupError |
| 123 | |
Benjamin Peterson | fa0d703 | 2009-06-01 22:42:33 +0000 | [diff] [blame] | 124 | The base class for the exceptions that are raised when a key or index used on |
| 125 | a mapping or sequence is invalid: :exc:`IndexError`, :exc:`KeyError`. This |
| 126 | can be raised directly by :func:`codecs.lookup`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 127 | |
| 128 | |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 129 | Concrete exceptions |
| 130 | ------------------- |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 131 | |
Georg Brandl | fbd1b22 | 2009-12-29 21:38:35 +0000 | [diff] [blame] | 132 | The following exceptions are the exceptions that are usually raised. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 133 | |
| 134 | .. exception:: AssertionError |
| 135 | |
| 136 | .. index:: statement: assert |
| 137 | |
| 138 | Raised when an :keyword:`assert` statement fails. |
| 139 | |
| 140 | |
| 141 | .. exception:: AttributeError |
| 142 | |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 143 | Raised when an attribute reference (see :ref:`attribute-references`) or |
| 144 | assignment fails. (When an object does not support attribute references or |
| 145 | attribute assignments at all, :exc:`TypeError` is raised.) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 146 | |
| 147 | |
| 148 | .. exception:: EOFError |
| 149 | |
Serhiy Storchaka | bfdcd43 | 2013-10-13 23:09:14 +0300 | [diff] [blame] | 150 | Raised when the :func:`input` function hits an end-of-file condition (EOF) |
| 151 | without reading any data. (N.B.: the :meth:`io.IOBase.read` and |
| 152 | :meth:`io.IOBase.readline` methods return an empty string when they hit EOF.) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 153 | |
| 154 | |
| 155 | .. exception:: FloatingPointError |
| 156 | |
Nathaniel J. Smith | 735ae8d | 2018-01-05 23:15:34 -0800 | [diff] [blame] | 157 | Not currently used. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 158 | |
| 159 | |
| 160 | .. exception:: GeneratorExit |
| 161 | |
Yury Selivanov | 66f8828 | 2015-06-24 11:04:15 -0400 | [diff] [blame] | 162 | Raised when a :term:`generator` or :term:`coroutine` is closed; |
| 163 | see :meth:`generator.close` and :meth:`coroutine.close`. It |
Christian Heimes | cbf3b5c | 2007-12-03 21:02:03 +0000 | [diff] [blame] | 164 | directly inherits from :exc:`BaseException` instead of :exc:`Exception` since |
| 165 | it is technically not an error. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 166 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 167 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 168 | .. exception:: ImportError |
| 169 | |
Eric Snow | c943265 | 2016-09-07 15:42:32 -0700 | [diff] [blame] | 170 | Raised when the :keyword:`import` statement has troubles trying to |
| 171 | load a module. Also raised when the "from list" in ``from ... import`` |
| 172 | has a name that cannot be found. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 173 | |
Brett Cannon | 79ec55e | 2012-04-12 20:24:54 -0400 | [diff] [blame] | 174 | The :attr:`name` and :attr:`path` attributes can be set using keyword-only |
| 175 | arguments to the constructor. When set they represent the name of the module |
| 176 | that was attempted to be imported and the path to any file which triggered |
| 177 | the exception, respectively. |
| 178 | |
| 179 | .. versionchanged:: 3.3 |
| 180 | Added the :attr:`name` and :attr:`path` attributes. |
| 181 | |
Eric Snow | c943265 | 2016-09-07 15:42:32 -0700 | [diff] [blame] | 182 | .. exception:: ModuleNotFoundError |
| 183 | |
| 184 | A subclass of :exc:`ImportError` which is raised by :keyword:`import` |
| 185 | when a module could not be located. It is also raised when ``None`` |
| 186 | is found in :data:`sys.modules`. |
| 187 | |
| 188 | .. versionadded:: 3.6 |
| 189 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 190 | |
| 191 | .. exception:: IndexError |
| 192 | |
Georg Brandl | 95817b3 | 2008-05-11 14:30:18 +0000 | [diff] [blame] | 193 | Raised when a sequence subscript is out of range. (Slice indices are |
| 194 | silently truncated to fall in the allowed range; if an index is not an |
| 195 | integer, :exc:`TypeError` is raised.) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 196 | |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 197 | .. XXX xref to sequences |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 198 | |
| 199 | |
| 200 | .. exception:: KeyError |
| 201 | |
| 202 | Raised when a mapping (dictionary) key is not found in the set of existing keys. |
| 203 | |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 204 | .. XXX xref to mapping objects? |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 205 | |
| 206 | |
| 207 | .. exception:: KeyboardInterrupt |
| 208 | |
| 209 | Raised when the user hits the interrupt key (normally :kbd:`Control-C` or |
Georg Brandl | 81ac1ce | 2007-08-31 17:17:17 +0000 | [diff] [blame] | 210 | :kbd:`Delete`). During execution, a check for interrupts is made |
| 211 | regularly. The exception inherits from :exc:`BaseException` so as to not be |
| 212 | accidentally caught by code that catches :exc:`Exception` and thus prevent |
| 213 | the interpreter from exiting. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 214 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 215 | |
| 216 | .. exception:: MemoryError |
| 217 | |
| 218 | Raised when an operation runs out of memory but the situation may still be |
| 219 | rescued (by deleting some objects). The associated value is a string indicating |
| 220 | what kind of (internal) operation ran out of memory. Note that because of the |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 221 | underlying memory management architecture (C's :c:func:`malloc` function), the |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 222 | interpreter may not always be able to completely recover from this situation; it |
| 223 | nevertheless raises an exception so that a stack traceback can be printed, in |
| 224 | case a run-away program was the cause. |
| 225 | |
| 226 | |
| 227 | .. exception:: NameError |
| 228 | |
| 229 | Raised when a local or global name is not found. This applies only to |
| 230 | unqualified names. The associated value is an error message that includes the |
| 231 | name that could not be found. |
| 232 | |
| 233 | |
| 234 | .. exception:: NotImplementedError |
| 235 | |
| 236 | This exception is derived from :exc:`RuntimeError`. In user defined base |
Ethan Furman | 20bd9f0 | 2016-08-05 15:10:16 -0700 | [diff] [blame] | 237 | classes, abstract methods should raise this exception when they require |
| 238 | derived classes to override the method, or while the class is being |
| 239 | developed to indicate that the real implementation still needs to be added. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 240 | |
Ethan Furman | 20bd9f0 | 2016-08-05 15:10:16 -0700 | [diff] [blame] | 241 | .. note:: |
| 242 | |
delirious-lettuce | 3378b20 | 2017-05-19 14:37:57 -0600 | [diff] [blame] | 243 | It should not be used to indicate that an operator or method is not |
Ethan Furman | 20bd9f0 | 2016-08-05 15:10:16 -0700 | [diff] [blame] | 244 | meant to be supported at all -- in that case either leave the operator / |
| 245 | method undefined or, if a subclass, set it to :data:`None`. |
| 246 | |
| 247 | .. note:: |
| 248 | |
| 249 | ``NotImplementedError`` and ``NotImplemented`` are not interchangeable, |
| 250 | even though they have similar names and purposes. See |
| 251 | :data:`NotImplemented` for details on when to use it. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 252 | |
Martin Panter | 5487c13 | 2015-10-26 11:05:42 +0000 | [diff] [blame] | 253 | .. exception:: OSError([arg]) |
| 254 | OSError(errno, strerror[, filename[, winerror[, filename2]]]) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 255 | |
Christian Heimes | a62da1d | 2008-01-12 19:39:10 +0000 | [diff] [blame] | 256 | .. index:: module: errno |
| 257 | |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 258 | This exception is raised when a system function returns a system-related |
| 259 | error, including I/O failures such as "file not found" or "disk full" |
Martin Panter | 5487c13 | 2015-10-26 11:05:42 +0000 | [diff] [blame] | 260 | (not for illegal argument types or other incidental errors). |
Christian Heimes | a62da1d | 2008-01-12 19:39:10 +0000 | [diff] [blame] | 261 | |
Martin Panter | 5487c13 | 2015-10-26 11:05:42 +0000 | [diff] [blame] | 262 | The second form of the constructor sets the corresponding attributes, |
| 263 | described below. The attributes default to :const:`None` if not |
| 264 | specified. For backwards compatibility, if three arguments are passed, |
| 265 | the :attr:`~BaseException.args` attribute contains only a 2-tuple |
| 266 | of the first two constructor arguments. |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 267 | |
Martin Panter | 5487c13 | 2015-10-26 11:05:42 +0000 | [diff] [blame] | 268 | The constructor often actually returns a subclass of :exc:`OSError`, as |
| 269 | described in `OS exceptions`_ below. The particular subclass depends on |
| 270 | the final :attr:`.errno` value. This behaviour only occurs when |
| 271 | constructing :exc:`OSError` directly or via an alias, and is not |
| 272 | inherited when subclassing. |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 273 | |
Martin Panter | 5487c13 | 2015-10-26 11:05:42 +0000 | [diff] [blame] | 274 | .. attribute:: errno |
| 275 | |
| 276 | A numeric error code from the C variable :c:data:`errno`. |
| 277 | |
| 278 | .. attribute:: winerror |
| 279 | |
| 280 | Under Windows, this gives you the native |
| 281 | Windows error code. The :attr:`.errno` attribute is then an approximate |
| 282 | translation, in POSIX terms, of that native error code. |
| 283 | |
| 284 | Under Windows, if the *winerror* constructor argument is an integer, |
| 285 | the :attr:`.errno` attribute is determined from the Windows error code, |
| 286 | and the *errno* argument is ignored. On other platforms, the |
| 287 | *winerror* argument is ignored, and the :attr:`winerror` attribute |
| 288 | does not exist. |
| 289 | |
| 290 | .. attribute:: strerror |
| 291 | |
| 292 | The corresponding error message, as provided by |
| 293 | the operating system. It is formatted by the C |
| 294 | functions :c:func:`perror` under POSIX, and :c:func:`FormatMessage` |
| 295 | under Windows. |
| 296 | |
| 297 | .. attribute:: filename |
| 298 | filename2 |
| 299 | |
| 300 | For exceptions that involve a file system path (such as :func:`open` or |
| 301 | :func:`os.unlink`), :attr:`filename` is the file name passed to the function. |
| 302 | For functions that involve two file system paths (such as |
| 303 | :func:`os.rename`), :attr:`filename2` corresponds to the second |
| 304 | file name passed to the function. |
Larry Hastings | b082731 | 2014-02-09 22:05:19 -0800 | [diff] [blame] | 305 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 306 | |
Antoine Pitrou | 195e702 | 2011-10-12 16:46:46 +0200 | [diff] [blame] | 307 | .. versionchanged:: 3.3 |
| 308 | :exc:`EnvironmentError`, :exc:`IOError`, :exc:`WindowsError`, |
Berker Peksag | 8fafc74 | 2016-04-11 12:23:04 +0300 | [diff] [blame] | 309 | :exc:`socket.error`, :exc:`select.error` and |
Martin Panter | 5487c13 | 2015-10-26 11:05:42 +0000 | [diff] [blame] | 310 | :exc:`mmap.error` have been merged into :exc:`OSError`, and the |
| 311 | constructor may return a subclass. |
Antoine Pitrou | 195e702 | 2011-10-12 16:46:46 +0200 | [diff] [blame] | 312 | |
Victor Stinner | 292c835 | 2012-10-30 02:17:38 +0100 | [diff] [blame] | 313 | .. versionchanged:: 3.4 |
Victor Stinner | 292c835 | 2012-10-30 02:17:38 +0100 | [diff] [blame] | 314 | The :attr:`filename` attribute is now the original file name passed to |
| 315 | the function, instead of the name encoded to or decoded from the |
Martin Panter | 5487c13 | 2015-10-26 11:05:42 +0000 | [diff] [blame] | 316 | filesystem encoding. Also, the *filename2* constructor argument and |
| 317 | attribute was added. |
Victor Stinner | 292c835 | 2012-10-30 02:17:38 +0100 | [diff] [blame] | 318 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 319 | |
| 320 | .. exception:: OverflowError |
| 321 | |
| 322 | Raised when the result of an arithmetic operation is too large to be |
Georg Brandl | ba956ae | 2007-11-29 17:24:34 +0000 | [diff] [blame] | 323 | represented. This cannot occur for integers (which would rather raise |
Terry Jan Reedy | b6d1f48 | 2014-06-16 03:31:00 -0400 | [diff] [blame] | 324 | :exc:`MemoryError` than give up). However, for historical reasons, |
| 325 | OverflowError is sometimes raised for integers that are outside a required |
| 326 | range. Because of the lack of standardization of floating point exception |
| 327 | handling in C, most floating point operations are not checked. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 328 | |
| 329 | |
Yury Selivanov | f488fb4 | 2015-07-03 01:04:23 -0400 | [diff] [blame] | 330 | .. exception:: RecursionError |
| 331 | |
| 332 | This exception is derived from :exc:`RuntimeError`. It is raised when the |
| 333 | interpreter detects that the maximum recursion depth (see |
| 334 | :func:`sys.getrecursionlimit`) is exceeded. |
| 335 | |
| 336 | .. versionadded:: 3.5 |
| 337 | Previously, a plain :exc:`RuntimeError` was raised. |
| 338 | |
| 339 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 340 | .. exception:: ReferenceError |
| 341 | |
| 342 | This exception is raised when a weak reference proxy, created by the |
| 343 | :func:`weakref.proxy` function, is used to access an attribute of the referent |
| 344 | after it has been garbage collected. For more information on weak references, |
| 345 | see the :mod:`weakref` module. |
| 346 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 347 | |
| 348 | .. exception:: RuntimeError |
| 349 | |
| 350 | Raised when an error is detected that doesn't fall in any of the other |
| 351 | categories. The associated value is a string indicating what precisely went |
Antoine Pitrou | 9527f16 | 2013-11-25 19:08:32 +0100 | [diff] [blame] | 352 | wrong. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 353 | |
| 354 | |
| 355 | .. exception:: StopIteration |
| 356 | |
Georg Brandl | c4a55fc | 2010-02-06 18:46:57 +0000 | [diff] [blame] | 357 | Raised by built-in function :func:`next` and an :term:`iterator`\'s |
Ezio Melotti | 1dd7c30 | 2012-10-12 13:45:38 +0300 | [diff] [blame] | 358 | :meth:`~iterator.__next__` method to signal that there are no further |
| 359 | items produced by the iterator. |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 360 | |
| 361 | The exception object has a single attribute :attr:`value`, which is |
| 362 | given as an argument when constructing the exception, and defaults |
| 363 | to :const:`None`. |
| 364 | |
Yury Selivanov | 66f8828 | 2015-06-24 11:04:15 -0400 | [diff] [blame] | 365 | When a :term:`generator` or :term:`coroutine` function |
| 366 | returns, a new :exc:`StopIteration` instance is |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 367 | raised, and the value returned by the function is used as the |
| 368 | :attr:`value` parameter to the constructor of the exception. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 369 | |
Yury Selivanov | 8170e8c | 2015-05-09 11:44:30 -0400 | [diff] [blame] | 370 | If a generator function defined in the presence of a ``from __future__ |
| 371 | import generator_stop`` directive raises :exc:`StopIteration`, it will be |
| 372 | converted into a :exc:`RuntimeError` (retaining the :exc:`StopIteration` |
| 373 | as the new exception's cause). |
| 374 | |
Nick Coghlan | 0ed8019 | 2012-01-14 14:43:24 +1000 | [diff] [blame] | 375 | .. versionchanged:: 3.3 |
| 376 | Added ``value`` attribute and the ability for generator functions to |
| 377 | use it to return a value. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 378 | |
Yury Selivanov | 8170e8c | 2015-05-09 11:44:30 -0400 | [diff] [blame] | 379 | .. versionchanged:: 3.5 |
| 380 | Introduced the RuntimeError transformation. |
| 381 | |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 382 | .. exception:: StopAsyncIteration |
| 383 | |
| 384 | Must be raised by :meth:`__anext__` method of an |
| 385 | :term:`asynchronous iterator` object to stop the iteration. |
| 386 | |
| 387 | .. versionadded:: 3.5 |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 388 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 389 | .. exception:: SyntaxError |
| 390 | |
| 391 | Raised when the parser encounters a syntax error. This may occur in an |
| 392 | :keyword:`import` statement, in a call to the built-in functions :func:`exec` |
| 393 | or :func:`eval`, or when reading the initial script or standard input |
| 394 | (also interactively). |
| 395 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 396 | Instances of this class have attributes :attr:`filename`, :attr:`lineno`, |
| 397 | :attr:`offset` and :attr:`text` for easier access to the details. :func:`str` |
| 398 | of the exception instance returns only the message. |
| 399 | |
| 400 | |
Georg Brandl | 0bdfbfa | 2010-12-18 17:51:28 +0000 | [diff] [blame] | 401 | .. exception:: IndentationError |
| 402 | |
| 403 | Base class for syntax errors related to incorrect indentation. This is a |
| 404 | subclass of :exc:`SyntaxError`. |
| 405 | |
| 406 | |
| 407 | .. exception:: TabError |
| 408 | |
| 409 | Raised when indentation contains an inconsistent use of tabs and spaces. |
| 410 | This is a subclass of :exc:`IndentationError`. |
| 411 | |
| 412 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 413 | .. exception:: SystemError |
| 414 | |
| 415 | Raised when the interpreter finds an internal error, but the situation does not |
| 416 | look so serious to cause it to abandon all hope. The associated value is a |
| 417 | string indicating what went wrong (in low-level terms). |
| 418 | |
| 419 | You should report this to the author or maintainer of your Python interpreter. |
| 420 | Be sure to report the version of the Python interpreter (``sys.version``; it is |
| 421 | also printed at the start of an interactive Python session), the exact error |
| 422 | message (the exception's associated value) and if possible the source of the |
| 423 | program that triggered the error. |
| 424 | |
| 425 | |
| 426 | .. exception:: SystemExit |
| 427 | |
Berker Peksag | 77a6b20 | 2015-03-10 14:47:15 +0200 | [diff] [blame] | 428 | This exception is raised by the :func:`sys.exit` function. It inherits from |
| 429 | :exc:`BaseException` instead of :exc:`Exception` so that it is not accidentally |
| 430 | caught by code that catches :exc:`Exception`. This allows the exception to |
| 431 | properly propagate up and cause the interpreter to exit. When it is not |
| 432 | handled, the Python interpreter exits; no stack traceback is printed. The |
| 433 | constructor accepts the same optional argument passed to :func:`sys.exit`. |
| 434 | If the value is an integer, it specifies the system exit status (passed to |
| 435 | C's :c:func:`exit` function); if it is ``None``, the exit status is zero; if |
| 436 | it has another type (such as a string), the object's value is printed and |
Georg Brandl | 95817b3 | 2008-05-11 14:30:18 +0000 | [diff] [blame] | 437 | the exit status is one. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 438 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 439 | A call to :func:`sys.exit` is translated into an exception so that clean-up |
| 440 | handlers (:keyword:`finally` clauses of :keyword:`try` statements) can be |
| 441 | executed, and so that a debugger can execute a script without running the risk |
| 442 | of losing control. The :func:`os._exit` function can be used if it is |
| 443 | absolutely positively necessary to exit immediately (for example, in the child |
Serhiy Storchaka | bfdcd43 | 2013-10-13 23:09:14 +0300 | [diff] [blame] | 444 | process after a call to :func:`os.fork`). |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 445 | |
Berker Peksag | 77a6b20 | 2015-03-10 14:47:15 +0200 | [diff] [blame] | 446 | .. attribute:: code |
| 447 | |
| 448 | The exit status or error message that is passed to the constructor. |
| 449 | (Defaults to ``None``.) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 450 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 451 | |
| 452 | .. exception:: TypeError |
| 453 | |
| 454 | Raised when an operation or function is applied to an object of inappropriate |
| 455 | type. The associated value is a string giving details about the type mismatch. |
| 456 | |
Ethan Furman | 20bd9f0 | 2016-08-05 15:10:16 -0700 | [diff] [blame] | 457 | This exception may be raised by user code to indicate that an attempted |
| 458 | operation on an object is not supported, and is not meant to be. If an object |
| 459 | is meant to support a given operation but has not yet provided an |
| 460 | implementation, :exc:`NotImplementedError` is the proper exception to raise. |
| 461 | |
| 462 | Passing arguments of the wrong type (e.g. passing a :class:`list` when an |
| 463 | :class:`int` is expected) should result in a :exc:`TypeError`, but passing |
| 464 | arguments with the wrong value (e.g. a number outside expected boundaries) |
| 465 | should result in a :exc:`ValueError`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 466 | |
| 467 | .. exception:: UnboundLocalError |
| 468 | |
| 469 | Raised when a reference is made to a local variable in a function or method, but |
| 470 | no value has been bound to that variable. This is a subclass of |
| 471 | :exc:`NameError`. |
| 472 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 473 | |
| 474 | .. exception:: UnicodeError |
| 475 | |
| 476 | Raised when a Unicode-related encoding or decoding error occurs. It is a |
| 477 | subclass of :exc:`ValueError`. |
| 478 | |
Benjamin Peterson | 78f7e3a | 2012-12-02 11:33:06 -0500 | [diff] [blame] | 479 | :exc:`UnicodeError` has attributes that describe the encoding or decoding |
| 480 | error. For example, ``err.object[err.start:err.end]`` gives the particular |
| 481 | invalid input that the codec failed on. |
| 482 | |
| 483 | .. attribute:: encoding |
| 484 | |
| 485 | The name of the encoding that raised the error. |
| 486 | |
| 487 | .. attribute:: reason |
| 488 | |
| 489 | A string describing the specific codec error. |
| 490 | |
| 491 | .. attribute:: object |
| 492 | |
| 493 | The object the codec was attempting to encode or decode. |
| 494 | |
| 495 | .. attribute:: start |
| 496 | |
| 497 | The first index of invalid data in :attr:`object`. |
| 498 | |
| 499 | .. attribute:: end |
| 500 | |
| 501 | The index after the last invalid data in :attr:`object`. |
| 502 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 503 | |
| 504 | .. exception:: UnicodeEncodeError |
| 505 | |
| 506 | Raised when a Unicode-related error occurs during encoding. It is a subclass of |
| 507 | :exc:`UnicodeError`. |
| 508 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 509 | |
| 510 | .. exception:: UnicodeDecodeError |
| 511 | |
| 512 | Raised when a Unicode-related error occurs during decoding. It is a subclass of |
| 513 | :exc:`UnicodeError`. |
| 514 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 515 | |
| 516 | .. exception:: UnicodeTranslateError |
| 517 | |
| 518 | Raised when a Unicode-related error occurs during translating. It is a subclass |
| 519 | of :exc:`UnicodeError`. |
| 520 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 521 | |
| 522 | .. exception:: ValueError |
| 523 | |
| 524 | Raised when a built-in operation or function receives an argument that has the |
| 525 | right type but an inappropriate value, and the situation is not described by a |
| 526 | more precise exception such as :exc:`IndexError`. |
| 527 | |
| 528 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 529 | .. exception:: ZeroDivisionError |
| 530 | |
| 531 | Raised when the second argument of a division or modulo operation is zero. The |
| 532 | associated value is a string indicating the type of the operands and the |
| 533 | operation. |
| 534 | |
Georg Brandl | fbd1b22 | 2009-12-29 21:38:35 +0000 | [diff] [blame] | 535 | |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 536 | The following exceptions are kept for compatibility with previous versions; |
| 537 | starting from Python 3.3, they are aliases of :exc:`OSError`. |
| 538 | |
| 539 | .. exception:: EnvironmentError |
| 540 | |
| 541 | .. exception:: IOError |
| 542 | |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 543 | .. exception:: WindowsError |
| 544 | |
| 545 | Only available on Windows. |
| 546 | |
| 547 | |
| 548 | OS exceptions |
| 549 | ^^^^^^^^^^^^^ |
| 550 | |
| 551 | The following exceptions are subclasses of :exc:`OSError`, they get raised |
| 552 | depending on the system error code. |
| 553 | |
| 554 | .. exception:: BlockingIOError |
| 555 | |
| 556 | Raised when an operation would block on an object (e.g. socket) set |
| 557 | for non-blocking operation. |
| 558 | Corresponds to :c:data:`errno` ``EAGAIN``, ``EALREADY``, |
| 559 | ``EWOULDBLOCK`` and ``EINPROGRESS``. |
| 560 | |
Antoine Pitrou | f55011f | 2011-10-12 18:57:23 +0200 | [diff] [blame] | 561 | In addition to those of :exc:`OSError`, :exc:`BlockingIOError` can have |
| 562 | one more attribute: |
| 563 | |
| 564 | .. attribute:: characters_written |
| 565 | |
| 566 | An integer containing the number of characters written to the stream |
| 567 | before it blocked. This attribute is available when using the |
| 568 | buffered I/O classes from the :mod:`io` module. |
| 569 | |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 570 | .. exception:: ChildProcessError |
| 571 | |
| 572 | Raised when an operation on a child process failed. |
| 573 | Corresponds to :c:data:`errno` ``ECHILD``. |
| 574 | |
| 575 | .. exception:: ConnectionError |
| 576 | |
Ezio Melotti | b24d3cf | 2012-10-21 03:22:05 +0300 | [diff] [blame] | 577 | A base class for connection-related issues. |
| 578 | |
| 579 | Subclasses are :exc:`BrokenPipeError`, :exc:`ConnectionAbortedError`, |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 580 | :exc:`ConnectionRefusedError` and :exc:`ConnectionResetError`. |
| 581 | |
Ezio Melotti | b24d3cf | 2012-10-21 03:22:05 +0300 | [diff] [blame] | 582 | .. exception:: BrokenPipeError |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 583 | |
Ezio Melotti | b24d3cf | 2012-10-21 03:22:05 +0300 | [diff] [blame] | 584 | A subclass of :exc:`ConnectionError`, raised when trying to write on a |
| 585 | pipe while the other end has been closed, or trying to write on a socket |
| 586 | which has been shutdown for writing. |
| 587 | Corresponds to :c:data:`errno` ``EPIPE`` and ``ESHUTDOWN``. |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 588 | |
Ezio Melotti | b24d3cf | 2012-10-21 03:22:05 +0300 | [diff] [blame] | 589 | .. exception:: ConnectionAbortedError |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 590 | |
Ezio Melotti | b24d3cf | 2012-10-21 03:22:05 +0300 | [diff] [blame] | 591 | A subclass of :exc:`ConnectionError`, raised when a connection attempt |
| 592 | is aborted by the peer. |
| 593 | Corresponds to :c:data:`errno` ``ECONNABORTED``. |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 594 | |
Ezio Melotti | b24d3cf | 2012-10-21 03:22:05 +0300 | [diff] [blame] | 595 | .. exception:: ConnectionRefusedError |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 596 | |
Ezio Melotti | b24d3cf | 2012-10-21 03:22:05 +0300 | [diff] [blame] | 597 | A subclass of :exc:`ConnectionError`, raised when a connection attempt |
| 598 | is refused by the peer. |
| 599 | Corresponds to :c:data:`errno` ``ECONNREFUSED``. |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 600 | |
Ezio Melotti | b24d3cf | 2012-10-21 03:22:05 +0300 | [diff] [blame] | 601 | .. exception:: ConnectionResetError |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 602 | |
Ezio Melotti | b24d3cf | 2012-10-21 03:22:05 +0300 | [diff] [blame] | 603 | A subclass of :exc:`ConnectionError`, raised when a connection is |
| 604 | reset by the peer. |
| 605 | Corresponds to :c:data:`errno` ``ECONNRESET``. |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 606 | |
| 607 | .. exception:: FileExistsError |
| 608 | |
| 609 | Raised when trying to create a file or directory which already exists. |
| 610 | Corresponds to :c:data:`errno` ``EEXIST``. |
| 611 | |
| 612 | .. exception:: FileNotFoundError |
| 613 | |
| 614 | Raised when a file or directory is requested but doesn't exist. |
| 615 | Corresponds to :c:data:`errno` ``ENOENT``. |
| 616 | |
| 617 | .. exception:: InterruptedError |
| 618 | |
| 619 | Raised when a system call is interrupted by an incoming signal. |
Victor Stinner | f70e1ca | 2015-03-30 21:16:11 +0200 | [diff] [blame] | 620 | Corresponds to :c:data:`errno` :py:data:`~errno.EINTR`. |
| 621 | |
| 622 | .. versionchanged:: 3.5 |
| 623 | Python now retries system calls when a syscall is interrupted by a |
| 624 | signal, except if the signal handler raises an exception (see :pep:`475` |
| 625 | for the rationale), instead of raising :exc:`InterruptedError`. |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 626 | |
| 627 | .. exception:: IsADirectoryError |
| 628 | |
| 629 | Raised when a file operation (such as :func:`os.remove`) is requested |
| 630 | on a directory. |
| 631 | Corresponds to :c:data:`errno` ``EISDIR``. |
| 632 | |
| 633 | .. exception:: NotADirectoryError |
| 634 | |
| 635 | Raised when a directory operation (such as :func:`os.listdir`) is requested |
| 636 | on something which is not a directory. |
| 637 | Corresponds to :c:data:`errno` ``ENOTDIR``. |
| 638 | |
| 639 | .. exception:: PermissionError |
| 640 | |
| 641 | Raised when trying to run an operation without the adequate access |
| 642 | rights - for example filesystem permissions. |
| 643 | Corresponds to :c:data:`errno` ``EACCES`` and ``EPERM``. |
| 644 | |
| 645 | .. exception:: ProcessLookupError |
| 646 | |
| 647 | Raised when a given process doesn't exist. |
| 648 | Corresponds to :c:data:`errno` ``ESRCH``. |
| 649 | |
| 650 | .. exception:: TimeoutError |
| 651 | |
| 652 | Raised when a system function timed out at the system level. |
| 653 | Corresponds to :c:data:`errno` ``ETIMEDOUT``. |
| 654 | |
| 655 | .. versionadded:: 3.3 |
| 656 | All the above :exc:`OSError` subclasses were added. |
| 657 | |
| 658 | |
| 659 | .. seealso:: |
| 660 | |
| 661 | :pep:`3151` - Reworking the OS and IO exception hierarchy |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 662 | |
| 663 | |
Nick Coghlan | 9b99747 | 2018-01-08 12:45:02 +1000 | [diff] [blame] | 664 | .. _warning-categories-as-exceptions: |
| 665 | |
Antoine Pitrou | f9c7746 | 2011-10-12 16:02:00 +0200 | [diff] [blame] | 666 | Warnings |
| 667 | -------- |
| 668 | |
Nick Coghlan | 9b99747 | 2018-01-08 12:45:02 +1000 | [diff] [blame] | 669 | The following exceptions are used as warning categories; see the |
| 670 | :ref:`warning-categories` documentation for more details. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 671 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 672 | .. exception:: Warning |
| 673 | |
| 674 | Base class for warning categories. |
| 675 | |
| 676 | |
| 677 | .. exception:: UserWarning |
| 678 | |
| 679 | Base class for warnings generated by user code. |
| 680 | |
| 681 | |
| 682 | .. exception:: DeprecationWarning |
| 683 | |
Nick Coghlan | 9b99747 | 2018-01-08 12:45:02 +1000 | [diff] [blame] | 684 | Base class for warnings about deprecated features when those warnings are |
| 685 | intended for other Python developers. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 686 | |
| 687 | |
| 688 | .. exception:: PendingDeprecationWarning |
| 689 | |
Nick Coghlan | 9b99747 | 2018-01-08 12:45:02 +1000 | [diff] [blame] | 690 | Base class for warnings about features which will be deprecated in the |
| 691 | future. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 692 | |
| 693 | |
| 694 | .. exception:: SyntaxWarning |
| 695 | |
Martin Panter | d21e0b5 | 2015-10-10 10:36:22 +0000 | [diff] [blame] | 696 | Base class for warnings about dubious syntax. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 697 | |
| 698 | |
| 699 | .. exception:: RuntimeWarning |
| 700 | |
| 701 | Base class for warnings about dubious runtime behavior. |
| 702 | |
| 703 | |
| 704 | .. exception:: FutureWarning |
| 705 | |
Nick Coghlan | 9b99747 | 2018-01-08 12:45:02 +1000 | [diff] [blame] | 706 | Base class for warnings about deprecated features when those warnings are |
| 707 | intended for end users of applications that are written in Python. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 708 | |
| 709 | |
| 710 | .. exception:: ImportWarning |
| 711 | |
| 712 | Base class for warnings about probable mistakes in module imports. |
| 713 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 714 | |
| 715 | .. exception:: UnicodeWarning |
| 716 | |
| 717 | Base class for warnings related to Unicode. |
| 718 | |
Georg Brandl | 08be72d | 2010-10-24 15:11:22 +0000 | [diff] [blame] | 719 | |
Guido van Rossum | 98297ee | 2007-11-06 21:34:58 +0000 | [diff] [blame] | 720 | .. exception:: BytesWarning |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 721 | |
Serhiy Storchaka | bfdcd43 | 2013-10-13 23:09:14 +0300 | [diff] [blame] | 722 | Base class for warnings related to :class:`bytes` and :class:`bytearray`. |
Guido van Rossum | 98297ee | 2007-11-06 21:34:58 +0000 | [diff] [blame] | 723 | |
Georg Brandl | 08be72d | 2010-10-24 15:11:22 +0000 | [diff] [blame] | 724 | |
| 725 | .. exception:: ResourceWarning |
| 726 | |
Nick Coghlan | 9b99747 | 2018-01-08 12:45:02 +1000 | [diff] [blame] | 727 | Base class for warnings related to resource usage. Ignored by the default |
| 728 | warning filters. |
Georg Brandl | 08be72d | 2010-10-24 15:11:22 +0000 | [diff] [blame] | 729 | |
| 730 | .. versionadded:: 3.2 |
| 731 | |
| 732 | |
| 733 | |
Alexandre Vassalotti | c22c6f2 | 2009-07-21 00:51:58 +0000 | [diff] [blame] | 734 | Exception hierarchy |
| 735 | ------------------- |
Guido van Rossum | 98297ee | 2007-11-06 21:34:58 +0000 | [diff] [blame] | 736 | |
| 737 | The class hierarchy for built-in exceptions is: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 738 | |
| 739 | .. literalinclude:: ../../Lib/test/exception_hierarchy.txt |