chunk_id large_stringlengths 36 36 | doc_type large_stringclasses 2
values | category large_stringclasses 17
values | document large_stringclasses 50
values | version_raw large_stringclasses 590
values | chunk_index int64 0 262 | text large_stringlengths 11 5.69k | file_path large_stringclasses 882
values |
|---|---|---|---|---|---|---|---|
b9d01447-8d7f-56bc-9b13-6c5ab34393eb | docs | python | python_exceptions | 312 | 0 | # Built-in Exceptions¶
Source: https://docs.python.org/3.12/library/exceptions.html
Version: 3.12
In Python, all exceptions must be instances of a class that derives from
[`BaseException`](#BaseException "BaseException"). In a [`try`](../reference/compound_stmts.html#try) statement with an [`except`](../reference/com... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
7502105d-1d24-5ec1-a006-b87b18fe3cbf | docs | python | python_exceptions | 312 | 1 | class’s constructor.
User code can raise built-in exceptions. This can be used to test an exception
handler or to report an error condition “just like” the situation in which the
interpreter raises the same exception; but beware that there is nothing to
prevent user code from raising an inappropriate error.
The built... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
d7eefd72-7ea7-5c7d-b7ca-e7a29b866208 | docs | python | python_exceptions | 312 | 2 | BaseException.\_\_cause\_\_[¶](#BaseException.__cause__ "Link to this definition")
BaseException.\_\_suppress\_context\_\_[¶](#BaseException.__suppress_context__ "Link to this definition")
: When raising a new exception while another exception
is already being handled, the new exception’s
`__context__` attri... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
dd1e555f-e454-5d67-b082-cd645ea242c3 | docs | python | python_exceptions | 312 | 3 | `__cause__` also implicitly sets the `__suppress_context__`
attribute to `True`, so that using `raise new_exc from None`
effectively replaces the old exception with the new one for display
purposes (e.g. converting [`KeyError`](#KeyError "KeyError") to [`AttributeError`](#AttributeError "AttributeError"... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
81b40ed2-8dc5-5f08-a7dd-516715be4f6e | docs | python | python_exceptions | 312 | 4 | ## Inheriting from built-in exceptions[¶](#inheriting-from-built-in-exceptions "Link to this heading")
User code can create subclasses that inherit from an exception type.
It’s recommended to only subclass one exception type at a time to avoid
any possible conflicts between how the bases handle the `args`
attribute, a... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
885721a2-1eb1-5780-98a4-26d2f57fd280 | docs | python | python_exceptions | 312 | 5 | ## Base classes[¶](#base-classes "Link to this heading")
The following exceptions are used mostly as base classes for other exceptions.
*exception* BaseException[¶](#BaseException "Link to this definition")
: The base class for all built-in exceptions. It is not meant to be directly
inherited by user-defined cl... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
59057a70-a16b-54ae-be5f-a3da2063ce29 | docs | python | python_exceptions | 312 | 6 | with\_traceback(*tb*)[¶](#BaseException.with_traceback "Link to this definition")
: This method sets *tb* as the new traceback for the exception and returns
the exception object. It was more commonly used before the exception
chaining features of [**PEP 3134**](https://peps.python.org/pep-3134... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
2422f526-bddf-537b-946f-589e00abba65 | docs | python | python_exceptions | 312 | 7 | : A writable field that holds the
[traceback object](../reference/datamodel.html#traceback-objects) associated with this
exception. See also: [The raise statement](../reference/simple_stmts.html#raise).
add\_note(*note*)[¶](#BaseException.add_note "Link to this definition")
: Add the st... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
f46fc685-01bd-5669-97f4-a92ede6ba1f4 | docs | python | python_exceptions | 312 | 8 | : All built-in, non-system-exiting exceptions are derived from this class. All
user-defined exceptions should also be derived from this class.
*exception* ArithmeticError[¶](#ArithmeticError "Link to this definition")
: The base class for those built-in exceptions that are raised for various
arithmetic err... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
9a1fdc7e-9113-55ee-b62d-52727764af45 | docs | python | python_exceptions | 312 | 9 | can be raised directly by [`codecs.lookup()`](codecs.html#codecs.lookup "codecs.lookup").
## Concrete exceptions[¶](#concrete-exceptions "Link to this heading")
The following exceptions are the exceptions that are usually raised.
*exception* AssertionError[¶](#AssertionError "Link to this definition")
: Raised... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
b4338963-9460-5deb-acae-92c565f33234 | docs | python | python_exceptions | 312 | 10 | Changed in version 3.10: Added the `name` and `obj` attributes.
*exception* EOFError[¶](#EOFError "Link to this definition")
: Raised when the [`input()`](functions.html#input "input") function hits an end-of-file condition (EOF)
without reading any data. (N.B.: the `io.IOBase.read()` and
[`io.IOBase.rea... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
04524cd6-8d89-53e5-ad13-d3ff4ebbeee2 | docs | python | python_exceptions | 312 | 11 | directly inherits from [`BaseException`](#BaseException "BaseException") instead of [`Exception`](#Exception "Exception") since
it is technically not an error.
*exception* ImportError[¶](#ImportError "Link to this definition")
: Raised when the [`import`](../reference/simple_stmts.html#import) statement has ... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
416c6593-2ec6-55a8-a05a-6f0ae9c0b610 | docs | python | python_exceptions | 312 | 12 | : A subclass of [`ImportError`](#ImportError "ImportError") which is raised by [`import`](../reference/simple_stmts.html#import)
when a module could not be located. It is also raised when `None`
is found in [`sys.modules`](sys.html#sys.modules "sys.modules").
Added in version 3.6.
*exception* IndexError... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
e6a0cf50-bfde-5271-b3ca-7e7490c81f01 | docs | python | python_exceptions | 312 | 13 | regularly. The exception inherits from [`BaseException`](#BaseException "BaseException") so as to not be
accidentally caught by code that catches [`Exception`](#Exception "Exception") and thus prevent
the interpreter from exiting.
Note
Catching a [`KeyboardInterrupt`](#KeyboardInterrupt "KeyboardI... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
d3e88cfe-2f1a-544e-8be9-f392f22f877f | docs | python | python_exceptions | 312 | 14 | what kind of (internal) operation ran out of memory. Note that because of the
underlying memory management architecture (C’s `malloc()` function), the
interpreter may not always be able to completely recover from this situation; it
nevertheless raises an exception so that a stack traceback can be printe... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
34c6f944-eb26-5764-8a15-12d9d3ae626b | docs | python | python_exceptions | 312 | 15 | : This exception is derived from [`RuntimeError`](#RuntimeError "RuntimeError"). In user defined base
classes, abstract methods should raise this exception when they require
derived classes to override the method, or while the class is being
developed to indicate that the real implementation still needs t... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
6fe658ed-e474-589e-b8f5-5a5a0c8f4f06 | docs | python | python_exceptions | 312 | 16 | : This exception is raised when a system function returns a system-related
error, including I/O failures such as “file not found” or “disk full”
(not for illegal argument types or other incidental errors).
The second form of the constructor sets the corresponding attributes,
described below. The attr... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
4f896ca9-f088-50d7-845f-318bf25fd8c6 | docs | python | python_exceptions | 312 | 17 | errno[¶](#OSError.errno "Link to this definition")
: A numeric error code from the C variable `errno`.
winerror[¶](#OSError.winerror "Link to this definition")
: Under Windows, this gives you the native
Windows error code. The [`errno`](#OSError.errno "OSError.errno") attribute is then an a... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
7ec9004a-bad0-51ec-bd62-3974b5ed7cd4 | docs | python | python_exceptions | 312 | 18 | under Windows.
filename[¶](#OSError.filename "Link to this definition")
filename2[¶](#OSError.filename2 "Link to this definition")
: For exceptions that involve a file system path (such as [`open()`](functions.html#open "open") or
[`os.unlink()`](os.html#os.unlink "os.unlink")), [`filena... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
3e458693-ad74-58ab-821e-5819e26c9bb6 | docs | python | python_exceptions | 312 | 19 | constructor may return a subclass.
Changed in version 3.4: The [`filename`](#OSError.filename "OSError.filename") attribute is now the original file name passed to
the function, instead of the name encoded to or decoded from the
[filesystem encoding and error handler](../glossary.html#term-filesystem-e... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
443030ff-7b9b-5e9d-a0cc-71658d8673e7 | docs | python | python_exceptions | 312 | 20 | *exception* RecursionError[¶](#RecursionError "Link to this definition")
: This exception is derived from [`RuntimeError`](#RuntimeError "RuntimeError"). It is raised when the
interpreter detects that the maximum recursion depth (see
[`sys.getrecursionlimit()`](sys.html#sys.getrecursionlimit "sys.getrecursion... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
2a0ab4ab-abdb-5060-a443-e1babc2da956 | docs | python | python_exceptions | 312 | 21 | : Raised when an error is detected that doesn’t fall in any of the other
categories. The associated value is a string indicating what precisely went
wrong.
*exception* StopIteration[¶](#StopIteration "Link to this definition")
: Raised by built-in function [`next()`](functions.html#next "next") and an [ite... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
2c9338ee-b5f8-51f8-a3b1-f3b001580474 | docs | python | python_exceptions | 312 | 22 | raised, and the value returned by the function is used as the
[`value`](#StopIteration.value "StopIteration.value") parameter to the constructor of the exception.
If a generator code directly or indirectly raises [`StopIteration`](#StopIteration "StopIteration"),
it is converted into a [`RuntimeError`]... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
35398028-8a37-5002-9038-2fd909e51f95 | docs | python | python_exceptions | 312 | 23 | *exception* StopAsyncIteration[¶](#StopAsyncIteration "Link to this definition")
: Must be raised by [`__anext__()`](../reference/datamodel.html#object.__anext__ "object.__anext__") method of an
[asynchronous iterator](../glossary.html#term-asynchronous-iterator) object to stop the iteration.
Added in versio... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
d345ea35-5499-52ce-a502-72bc5141dac3 | docs | python | python_exceptions | 312 | 24 | filename[¶](#SyntaxError.filename "Link to this definition")
: The name of the file the syntax error occurred in.
lineno[¶](#SyntaxError.lineno "Link to this definition")
: Which line number in the file the error occurred in. This is
1-indexed: the first line in the file has a `lineno` of 1... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
2ec981dd-8864-5f45-a51d-bd5b81722da6 | docs | python | python_exceptions | 312 | 25 | 1-indexed: the first character in the line has an `offset` of 1.
For errors in f-string fields, the message is prefixed by “f-string: ”
and the offsets are offsets in a text constructed from the replacement
expression. For example, compiling f’Bad {a b} field’ results in this
args attribute: (‘... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
959c9409-e297-51e1-9804-5ea3ba8f840b | docs | python | python_exceptions | 312 | 26 | *exception* SystemError[¶](#SystemError "Link to this definition")
: Raised when the interpreter finds an internal error, but the situation does not
look so serious to cause it to abandon all hope. The associated value is a
string indicating what went wrong (in low-level terms). In [CPython](../glossary.html#... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
9ebe7f7e-42b2-507c-a802-fc4b976d5c51 | docs | python | python_exceptions | 312 | 27 | : This exception is raised by the [`sys.exit()`](sys.html#sys.exit "sys.exit") function. It inherits from
[`BaseException`](#BaseException "BaseException") instead of [`Exception`](#Exception "Exception") so that it is not accidentally
caught by code that catches [`Exception`](#Exception "Exception"). This al... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
8a750210-2e35-51e1-813c-5071330d6c69 | docs | python | python_exceptions | 312 | 28 | handlers ([`finally`](../reference/compound_stmts.html#finally) clauses of [`try`](../reference/compound_stmts.html#try) statements) can be
executed, and so that a debugger can execute a script without running the risk
of losing control. The [`os._exit()`](os.html#os._exit "os._exit") function can be used i... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
f3f1c4a9-7eec-5e1f-81e2-943baba74b40 | docs | python | python_exceptions | 312 | 29 | operation on an object is not supported, and is not meant to be. If an object
is meant to support a given operation but has not yet provided an
implementation, [`NotImplementedError`](#NotImplementedError "NotImplementedError") is the proper exception to raise.
Passing arguments of the wrong type (e.g.... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
6e743324-9af1-56d6-947a-354d15f17bec | docs | python | python_exceptions | 312 | 30 | : Raised when a Unicode-related encoding or decoding error occurs. It is a
subclass of [`ValueError`](#ValueError "ValueError").
[`UnicodeError`](#UnicodeError "UnicodeError") has attributes that describe the encoding or decoding
error. For example, `err.object[err.start:err.end]` gives the particular
... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
7a9c251c-57c1-5cbc-9f7a-ac34ae1d5669 | docs | python | python_exceptions | 312 | 31 | : The index after the last invalid data in [`object`](functions.html#object "object").
*exception* UnicodeEncodeError[¶](#UnicodeEncodeError "Link to this definition")
: Raised when a Unicode-related error occurs during encoding. It is a subclass of
[`UnicodeError`](#UnicodeError "UnicodeError").
*excepti... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
d30add2a-eb78-564c-b030-41c75e14ec08 | docs | python | python_exceptions | 312 | 32 | more precise exception such as [`IndexError`](#IndexError "IndexError").
*exception* ZeroDivisionError[¶](#ZeroDivisionError "Link to this definition")
: Raised when the second argument of a division or modulo operation is zero. The
associated value is a string indicating the type of the operands and the
... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
7f5bc528-da5b-5dc2-b93e-3a2f89d7d54a | docs | python | python_exceptions | 312 | 33 | : Raised when an operation would block on an object (e.g. socket) set
for non-blocking operation.
Corresponds to `errno` [`EAGAIN`](errno.html#errno.EAGAIN "errno.EAGAIN"), [`EALREADY`](errno.html#errno.EALREADY "errno.EALREADY"),
[`EWOULDBLOCK`](errno.html#errno.EWOULDBLOCK "errno.EWOULDBLOCK") and [`EIN... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
b11adc9e-13fd-553e-b0c6-2647fef84ca8 | docs | python | python_exceptions | 312 | 34 | Corresponds to `errno` [`ECHILD`](errno.html#errno.ECHILD "errno.ECHILD").
*exception* ConnectionError[¶](#ConnectionError "Link to this definition")
: A base class for connection-related issues.
Subclasses are [`BrokenPipeError`](#BrokenPipeError "BrokenPipeError"), [`ConnectionAbortedError`](#ConnectionAb... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
77be38d6-d902-5752-b029-867dd8991d6e | docs | python | python_exceptions | 312 | 35 | *exception* ConnectionAbortedError[¶](#ConnectionAbortedError "Link to this definition")
: A subclass of [`ConnectionError`](#ConnectionError "ConnectionError"), raised when a connection attempt
is aborted by the peer.
Corresponds to `errno` [`ECONNABORTED`](errno.html#errno.ECONNABORTED "errno.ECONNABORTED")... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
44a67ca9-2dc6-5e9f-b47c-7bb53e0a17a6 | docs | python | python_exceptions | 312 | 36 | : Raised when trying to create a file or directory which already exists.
Corresponds to `errno` [`EEXIST`](errno.html#errno.EEXIST "errno.EEXIST").
*exception* FileNotFoundError[¶](#FileNotFoundError "Link to this definition")
: Raised when a file or directory is requested but doesn’t exist.
Corresponds to... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
f62440f7-a7f8-5fe9-9eac-12e4ecbf2066 | docs | python | python_exceptions | 312 | 37 | : Raised when a file operation (such as [`os.remove()`](os.html#os.remove "os.remove")) is requested
on a directory.
Corresponds to `errno` [`EISDIR`](errno.html#errno.EISDIR "errno.EISDIR").
*exception* NotADirectoryError[¶](#NotADirectoryError "Link to this definition")
: Raised when a directory operatio... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
8d13fb8b-4aa0-5f0f-825f-877bfe467102 | docs | python | python_exceptions | 312 | 38 | [`EPERM`](errno.html#errno.EPERM "errno.EPERM"), and [`ENOTCAPABLE`](errno.html#errno.ENOTCAPABLE "errno.ENOTCAPABLE").
Changed in version 3.11.1: WASI’s [`ENOTCAPABLE`](errno.html#errno.ENOTCAPABLE "errno.ENOTCAPABLE") is now mapped to
[`PermissionError`](#PermissionError "PermissionError").
*exception* ... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
898f8a8c-2c7f-5382-90a9-92d7322075d7 | docs | python | python_exceptions | 312 | 39 | ## Warnings[¶](#warnings "Link to this heading")
The following exceptions are used as warning categories; see the
[Warning Categories](warnings.html#warning-categories) documentation for more details.
*exception* Warning[¶](#Warning "Link to this definition")
: Base class for warning categories.
*exception* UserWa... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
d533dee4-56bc-5530-b2ba-1fcff2f593dd | docs | python | python_exceptions | 312 | 40 | *exception* PendingDeprecationWarning[¶](#PendingDeprecationWarning "Link to this definition")
: Base class for warnings about features which are obsolete and
expected to be deprecated in the future, but are not deprecated
at the moment.
This class is rarely used as emitting a warning about a possible
... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
c1433e29-bf07-5360-ad41-d53b1b3cf396 | docs | python | python_exceptions | 312 | 41 | *exception* FutureWarning[¶](#FutureWarning "Link to this definition")
: Base class for warnings about deprecated features when those warnings are
intended for end users of applications that are written in Python.
*exception* ImportWarning[¶](#ImportWarning "Link to this definition")
: Base class for warnings ... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
22dc9657-5a59-5462-b6af-80c732dc644b | docs | python | python_exceptions | 312 | 42 | : Base class for warnings related to [`bytes`](stdtypes.html#bytes "bytes") and [`bytearray`](stdtypes.html#bytearray "bytearray").
*exception* ResourceWarning[¶](#ResourceWarning "Link to this definition")
: Base class for warnings related to resource usage.
Ignored by the default warning filters. Enabling t... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
95790231-cabb-5dae-9336-4897ebcf1214 | docs | python | python_exceptions | 312 | 43 | *exception* BaseExceptionGroup(*msg*, *excs*)[¶](#BaseExceptionGroup "Link to this definition")
: Both of these exception types wrap the exceptions in the sequence `excs`.
The `msg` parameter must be a string. The difference between the two
classes is that [`BaseExceptionGroup`](#BaseExceptionGroup "BaseExcep... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
73386bf4-c7ec-5df1-be90-fee075819d71 | docs | python | python_exceptions | 312 | 44 | rather than a [`BaseExceptionGroup`](#BaseExceptionGroup "BaseExceptionGroup") if all contained exceptions are
[`Exception`](#Exception "Exception") instances, so it can be used to make the selection
automatic. The [`ExceptionGroup`](#ExceptionGroup "ExceptionGroup") constructor, on the other hand,
rais... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
019e9c91-e130-586e-a460-c90ff979b82c | docs | python | python_exceptions | 312 | 45 | current group that match *condition*, or `None` if the result is empty.
The condition can be either a function that accepts an exception and returns
true for those that should be in the subgroup, or it can be an exception type
or a tuple of exception types, which is used to check for a ... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
0d20c59f-af34-5997-a196-a2479efcc1f9 | docs | python | python_exceptions | 312 | 46 | The condition is checked for all exceptions in the nested exception group,
including the top-level and any nested exception groups. If the condition is
true for such an exception group, it is included in the result in full.
split(*condition*)[¶](#BaseExceptionGroup.split "Link to this defin... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
f9cecb54-b69c-5295-b6c2-e3175f888dff | docs | python | python_exceptions | 312 | 47 | are used in various contexts to break up an exception group. A
subclass needs to override it in order to make [`subgroup()`](#BaseExceptionGroup.subgroup "BaseExceptionGroup.subgroup")
and [`split()`](#BaseExceptionGroup.split "BaseExceptionGroup.split") return instances of the subclass rather
... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
60b885f4-5932-5a13-bfd7-c3cd4ef54413 | docs | python | python_exceptions | 312 | 48 | these fields do not need to be updated by [`derive()`](#BaseExceptionGroup.derive "BaseExceptionGroup.derive").
```None
>>> class MyGroup(ExceptionGroup):
... def derive(self, excs):
... return MyGroup(self.message, excs)
...
>>> e = MyGroup("eg", [Va... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
7e8f9e78-694c-598d-b83d-4deed297d93e | docs | python | python_exceptions | 312 | 49 | >>> rest, rest.__context__, rest.__cause__, rest.__notes__
(MyGroup('eg', [TypeError(2)]), Exception('context'), Exception('cause'), ['a note'])
>>> exc.__traceback__ is match.__traceback__ is rest.__traceback__
True
```
Note that [`BaseExceptionGroup`](#BaseExceptionGroup "... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
f42739fa-05f3-51c2-a43d-eacb359bcf55 | docs | python | python_exceptions | 312 | 50 | return Errors(excs, self.exit_code)
```
Like [`ExceptionGroup`](#ExceptionGroup "ExceptionGroup"), any subclass of [`BaseExceptionGroup`](#BaseExceptionGroup "BaseExceptionGroup") which
is also a subclass of [`Exception`](#Exception "Exception") can only wrap instances of
[`Exception`](#Excep... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
3d9337e1-5d20-5452-b019-c8541d705a19 | docs | python | python_exceptions | 312 | 51 | ├── NameError
│ └── UnboundLocalError
├── OSError
│ ├── BlockingIOError
│ ├── ChildProcessError
│ ├── ConnectionError
│ │ ├── BrokenPipeError
│ │ ├── ConnectionAbortedError
│ │ ├── ConnectionRefusedError
│ │ └── ConnectionRe... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
f8b8456a-44d6-5595-a72f-699e841509f6 | docs | python | python_exceptions | 312 | 52 | │ └── UnicodeTranslateError
└── Warning
├── BytesWarning
├── DeprecationWarning
├── EncodingWarning
├── FutureWarning
├── ImportWarning
├── PendingDeprecationWarning
├── ResourceWarning
├── RuntimeWarning
... | large_dataset/raw/docs/python/exceptions/exceptions_312.md |
2a4ee63f-f65c-57aa-8d8c-f65147548cd9 | docs | python | python_exceptions | 313 | 0 | # Built-in Exceptions¶
Source: https://docs.python.org/3.13/library/exceptions.html
Version: 3.13
In Python, all exceptions must be instances of a class that derives from
[`BaseException`](#BaseException "BaseException"). In a [`try`](../reference/compound_stmts.html#try) statement with an [`except`](../reference/com... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
ea664717-ff33-5ad4-a6aa-daef5109d89f | docs | python | python_exceptions | 313 | 1 | class’s constructor.
User code can raise built-in exceptions. This can be used to test an exception
handler or to report an error condition “just like” the situation in which the
interpreter raises the same exception; but beware that there is nothing to
prevent user code from raising an inappropriate error.
The built... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
b0a6bd95-3129-512a-862b-064bcb9fc478 | docs | python | python_exceptions | 313 | 2 | BaseException.\_\_cause\_\_[¶](#BaseException.__cause__ "Link to this definition")
BaseException.\_\_suppress\_context\_\_[¶](#BaseException.__suppress_context__ "Link to this definition")
: When raising a new exception while another exception
is already being handled, the new exception’s
`__context__` attri... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
802b0482-1aba-509f-9d19-213cfdeac2ec | docs | python | python_exceptions | 313 | 3 | `__cause__` also implicitly sets the `__suppress_context__`
attribute to `True`, so that using `raise new_exc from None`
effectively replaces the old exception with the new one for display
purposes (e.g. converting [`KeyError`](#KeyError "KeyError") to [`AttributeError`](#AttributeError "AttributeError"... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
210e7b01-0281-5434-9d03-b4e893d97032 | docs | python | python_exceptions | 313 | 4 | ## Inheriting from built-in exceptions[¶](#inheriting-from-built-in-exceptions "Link to this heading")
User code can create subclasses that inherit from an exception type.
It’s recommended to only subclass one exception type at a time to avoid
any possible conflicts between how the bases handle the `args`
attribute, a... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
97c37215-e4a3-5877-a844-04f15e467488 | docs | python | python_exceptions | 313 | 5 | ## Base classes[¶](#base-classes "Link to this heading")
The following exceptions are used mostly as base classes for other exceptions.
*exception* BaseException[¶](#BaseException "Link to this definition")
: The base class for all built-in exceptions. It is not meant to be directly
inherited by user-defined cl... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
22b4d14b-0130-5a67-813e-506ff490f945 | docs | python | python_exceptions | 313 | 6 | with\_traceback(*tb*)[¶](#BaseException.with_traceback "Link to this definition")
: This method sets *tb* as the new traceback for the exception and returns
the exception object. It was more commonly used before the exception
chaining features of [**PEP 3134**](https://peps.python.org/pep-3134... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
3fe7084e-8f7b-563b-b278-7b739b2fa5e4 | docs | python | python_exceptions | 313 | 7 | : A writable field that holds the
[traceback object](../reference/datamodel.html#traceback-objects) associated with this
exception. See also: [The raise statement](../reference/simple_stmts.html#raise).
add\_note(*note*)[¶](#BaseException.add_note "Link to this definition")
: Add the st... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
05081fac-5243-5eb0-b1ee-ce996f1b0fe2 | docs | python | python_exceptions | 313 | 8 | : All built-in, non-system-exiting exceptions are derived from this class. All
user-defined exceptions should also be derived from this class.
*exception* ArithmeticError[¶](#ArithmeticError "Link to this definition")
: The base class for those built-in exceptions that are raised for various
arithmetic err... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
e5a7f748-735d-5f32-a833-3b5a6c8678e0 | docs | python | python_exceptions | 313 | 9 | can be raised directly by [`codecs.lookup()`](codecs.html#codecs.lookup "codecs.lookup").
## Concrete exceptions[¶](#concrete-exceptions "Link to this heading")
The following exceptions are the exceptions that are usually raised.
*exception* AssertionError[¶](#AssertionError "Link to this definition")
: Raised... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
447c757d-3df2-500e-8cb9-cbb7b031d4db | docs | python | python_exceptions | 313 | 10 | obj[¶](#AttributeError.obj "Link to this definition")
: The object that was accessed for the named attribute.
Changed in version 3.10: Added the [`name`](#AttributeError.name "AttributeError.name") and [`obj`](#AttributeError.obj "AttributeError.obj") attributes.
*exception* EOFError[¶](#EOFError "Link ... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
fc1afd3f-1f37-5f66-8ed2-03fccf962e94 | docs | python | python_exceptions | 313 | 11 | see [`generator.close()`](../reference/expressions.html#generator.close "generator.close") and [`coroutine.close()`](../reference/datamodel.html#coroutine.close "coroutine.close"). It
directly inherits from [`BaseException`](#BaseException "BaseException") instead of [`Exception`](#Exception "Exception") since
... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
383b18f3-0ea2-56a5-a576-cdf7be2543a1 | docs | python | python_exceptions | 313 | 12 | Changed in version 3.3: Added the [`name`](#ImportError.name "ImportError.name") and [`path`](#ImportError.path "ImportError.path") attributes.
*exception* ModuleNotFoundError[¶](#ModuleNotFoundError "Link to this definition")
: A subclass of [`ImportError`](#ImportError "ImportError") which is raised by [`impor... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
bc062ab3-e491-5ecf-ab3a-2a9dc8fb124f | docs | python | python_exceptions | 313 | 13 | *exception* KeyboardInterrupt[¶](#KeyboardInterrupt "Link to this definition")
: Raised when the user hits the interrupt key (normally `Control`-`C` or
`Delete`). During execution, a check for interrupts is made
regularly. The exception inherits from [`BaseException`](#BaseException "BaseException") so as to ... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
a6b072a2-2bb9-5023-9f77-cf573e2cf113 | docs | python | python_exceptions | 313 | 14 | *exception* MemoryError[¶](#MemoryError "Link to this definition")
: Raised when an operation runs out of memory but the situation may still be
rescued (by deleting some objects). The associated value is a string indicating
what kind of (internal) operation ran out of memory. Note that because of the
unde... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
31446f83-b81a-5b91-b768-594e89c1de13 | docs | python | python_exceptions | 313 | 15 | : The name of the variable that was attempted to be accessed.
Changed in version 3.10: Added the [`name`](#NameError.name "NameError.name") attribute.
*exception* NotImplementedError[¶](#NotImplementedError "Link to this definition")
: This exception is derived from [`RuntimeError`](#RuntimeError "Runtime... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
aa98acde-10f9-52e7-99b5-1067da9953b7 | docs | python | python_exceptions | 313 | 16 | above; see [`NotImplemented`](constants.html#NotImplemented "NotImplemented") for details on correct usage of
the built-in constant.
*exception* OSError([*arg*])[¶](#OSError "Link to this definition")
*exception* OSError(*errno*, *strerror*[, *filename*[, *winerror*[, *filename2*]]])
: This exception is rai... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
355b53e0-a064-5217-b2a6-edfab08c590d | docs | python | python_exceptions | 313 | 17 | described in [OS exceptions](#os-exceptions) below. The particular subclass depends on
the final [`errno`](#OSError.errno "OSError.errno") value. This behaviour only occurs when
constructing [`OSError`](#OSError "OSError") directly or via an alias, and is not
inherited when subclassing.
errno[¶](#O... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
1946ac09-e364-5cca-8ec3-c2f7aab5b246 | docs | python | python_exceptions | 313 | 18 | *winerror* argument is ignored, and the [`winerror`](#OSError.winerror "OSError.winerror") attribute
does not exist.
strerror[¶](#OSError.strerror "Link to this definition")
: The corresponding error message, as provided by
the operating system. It is formatted by the C
functi... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
eac1f182-e166-51a3-82f3-3f2b4763cb3c | docs | python | python_exceptions | 313 | 19 | Changed in version 3.3: [`EnvironmentError`](#EnvironmentError "EnvironmentError"), [`IOError`](#IOError "IOError"), [`WindowsError`](#WindowsError "WindowsError"),
[`socket.error`](socket.html#socket.error "socket.error"), [`select.error`](select.html#select.error "select.error") and
`mmap.error` have been... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
f396eaae-5e20-5e59-91c1-79c82c09e197 | docs | python | python_exceptions | 313 | 20 | [`MemoryError`](#MemoryError "MemoryError") than give up). However, for historical reasons,
OverflowError is sometimes raised for integers that are outside a required
range. Because of the lack of standardization of floating-point exception
handling in C, most floating-point operations are not checked.
... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
5aab34b4-ac2b-53cf-8dbd-81b69f17d7a9 | docs | python | python_exceptions | 313 | 21 | Added in version 3.13: Previously, a plain [`RuntimeError`](#RuntimeError "RuntimeError") was raised.
*exception* RecursionError[¶](#RecursionError "Link to this definition")
: This exception is derived from [`RuntimeError`](#RuntimeError "RuntimeError"). It is raised when the
interpreter detects that the ma... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
67aacab3-5071-5784-a360-e57aabe56b13 | docs | python | python_exceptions | 313 | 22 | see the [`weakref`](weakref.html#module-weakref "weakref: Support for weak references and weak dictionaries.") module.
*exception* RuntimeError[¶](#RuntimeError "Link to this definition")
: Raised when an error is detected that doesn’t fall in any of the other
categories. The associated value is a string ind... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
c72e14ef-f4d9-56a4-b3be-f1527fab7cc6 | docs | python | python_exceptions | 313 | 23 | When a [generator](../glossary.html#term-generator) or [coroutine](../glossary.html#term-coroutine) function
returns, a new [`StopIteration`](#StopIteration "StopIteration") instance is
raised, and the value returned by the function is used as the
[`value`](#StopIteration.value "StopIteration.value") pa... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
29bf5b7d-154e-55ea-9c63-e2e28e4f7188 | docs | python | python_exceptions | 313 | 24 | Changed in version 3.7: Enable [**PEP 479**](https://peps.python.org/pep-0479/) for all code by default: a [`StopIteration`](#StopIteration "StopIteration")
error raised in a generator is transformed into a [`RuntimeError`](#RuntimeError "RuntimeError").
*exception* StopAsyncIteration[¶](#StopAsyncIteration "L... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
05bb9f7d-708c-5fcc-9b1b-b14cfd17aadd | docs | python | python_exceptions | 313 | 25 | or [`eval()`](functions.html#eval "eval"), or when reading the initial script or standard input
(also interactively).
The [`str()`](stdtypes.html#str "str") of the exception instance returns only the error message.
Details is a tuple whose members are also available as separate attributes.
filenam... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
ef4ac031-01e1-53dd-af6d-70854fd07bf6 | docs | python | python_exceptions | 313 | 26 | : Which line number in the file the error occurred ends in. This is
1-indexed: the first line in the file has a `lineno` of 1.
end\_offset[¶](#SyntaxError.end_offset "Link to this definition")
: The column in the end line where the error occurred finishes. This is
1-indexed: the first c... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
84a384f0-a8de-5413-8b33-e1a053667808 | docs | python | python_exceptions | 313 | 27 | subclass of [`SyntaxError`](#SyntaxError "SyntaxError").
*exception* TabError[¶](#TabError "Link to this definition")
: Raised when indentation contains an inconsistent use of tabs and spaces.
This is a subclass of [`IndentationError`](#IndentationError "IndentationError").
*exception* SystemError[¶](#Syste... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
35ab62e0-1b5e-5a16-90c8-ccda3f56c12a | docs | python | python_exceptions | 313 | 28 | also printed at the start of an interactive Python session), the exact error
message (the exception’s associated value) and if possible the source of the
program that triggered the error.
*exception* SystemExit[¶](#SystemExit "Link to this definition")
: This exception is raised by the [`sys.exit()`](sys... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
715a667f-209d-5f8f-97bb-7e2c9e85b575 | docs | python | python_exceptions | 313 | 29 | it has another type (such as a string), the object’s value is printed and
the exit status is one.
A call to [`sys.exit()`](sys.html#sys.exit "sys.exit") is translated into an exception so that clean-up
handlers ([`finally`](../reference/compound_stmts.html#finally) clauses of [`try`](../reference/compo... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
33eb01a6-8e9d-5f6f-aa79-409b5f126090 | docs | python | python_exceptions | 313 | 30 | type. The associated value is a string giving details about the type mismatch.
This exception may be raised by user code to indicate that an attempted
operation on an object is not supported, and is not meant to be. If an object
is meant to support a given operation but has not yet provided an
impl... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
3d63a796-cef0-5825-9a05-3cdb4a1e247e | docs | python | python_exceptions | 313 | 31 | no value has been bound to that variable. This is a subclass of
[`NameError`](#NameError "NameError").
*exception* UnicodeError[¶](#UnicodeError "Link to this definition")
: Raised when a Unicode-related encoding or decoding error occurs. It is a
subclass of [`ValueError`](#ValueError "ValueError").
... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
f42c0c4a-81b0-5542-8c96-f8c313a8840c | docs | python | python_exceptions | 313 | 32 | : The first index of invalid data in [`object`](functions.html#object "object").
end[¶](#UnicodeError.end "Link to this definition")
: The index after the last invalid data in [`object`](functions.html#object "object").
*exception* UnicodeEncodeError[¶](#UnicodeEncodeError "Link to this definition")
:... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
7b2b54d8-e44e-5af3-88de-25519325f939 | docs | python | python_exceptions | 313 | 33 | : Raised when an operation or function receives an argument that has the
right type but an inappropriate value, and the situation is not described by a
more precise exception such as [`IndexError`](#IndexError "IndexError").
*exception* ZeroDivisionError[¶](#ZeroDivisionError "Link to this definition")
: R... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
5085dacd-9ab0-527b-b245-0b9feda67945 | docs | python | python_exceptions | 313 | 34 | ### OS exceptions[¶](#os-exceptions "Link to this heading")
The following exceptions are subclasses of [`OSError`](#OSError "OSError"), they get raised
depending on the system error code.
*exception* BlockingIOError[¶](#BlockingIOError "Link to this definition")
: Raised when an operation would block on an object (... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
feb1b3a5-a4c1-5aec-89b0-b41cd8e07450 | docs | python | python_exceptions | 313 | 35 | before it blocked. This attribute is available when using the
buffered I/O classes from the [`io`](io.html#module-io "io: Core tools for working with streams.") module.
*exception* ChildProcessError[¶](#ChildProcessError "Link to this definition")
: Raised when an operation on a child process failed.... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
14d28954-714b-5f09-bf5d-7019067e4669 | docs | python | python_exceptions | 313 | 36 | pipe while the other end has been closed, or trying to write on a socket
which has been shutdown for writing.
Corresponds to `errno` [`EPIPE`](errno.html#errno.EPIPE "errno.EPIPE") and [`ESHUTDOWN`](errno.html#errno.ESHUTDOWN "errno.ESHUTDOWN").
*exception* ConnectionAbortedError[¶](#ConnectionAbortedError... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
32c39410-dbd2-504b-a54f-e0ba4f1bf8c9 | docs | python | python_exceptions | 313 | 37 | : A subclass of [`ConnectionError`](#ConnectionError "ConnectionError"), raised when a connection is
reset by the peer.
Corresponds to `errno` [`ECONNRESET`](errno.html#errno.ECONNRESET "errno.ECONNRESET").
*exception* FileExistsError[¶](#FileExistsError "Link to this definition")
: Raised when trying to c... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
8b2cf0f0-3468-5159-bd85-cee3d366ca8a | docs | python | python_exceptions | 313 | 38 | signal, except if the signal handler raises an exception (see [**PEP 475**](https://peps.python.org/pep-0475/)
for the rationale), instead of raising [`InterruptedError`](#InterruptedError "InterruptedError").
*exception* IsADirectoryError[¶](#IsADirectoryError "Link to this definition")
: Raised when a file... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
c12077c6-89be-593a-bcef-2d65dcc5b8fa | docs | python | python_exceptions | 313 | 39 | *exception* PermissionError[¶](#PermissionError "Link to this definition")
: Raised when trying to run an operation without the adequate access
rights - for example filesystem permissions.
Corresponds to `errno` [`EACCES`](errno.html#errno.EACCES "errno.EACCES"),
[`EPERM`](errno.html#errno.EPERM "errno.EP... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
197c7d3c-56b7-58b1-81dc-407736d82490 | docs | python | python_exceptions | 313 | 40 | Added in version 3.3: All the above [`OSError`](#OSError "OSError") subclasses were added.
See also
[**PEP 3151**](https://peps.python.org/pep-3151/) - Reworking the OS and IO exception hierarchy
## Warnings[¶](#warnings "Link to this heading")
The following exceptions are used as warning categories; see the
[Warni... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
25632152-e72f-56f1-a999-d8374f546be0 | docs | python | python_exceptions | 313 | 41 | this warning.
The deprecation policy is described in [**PEP 387**](https://peps.python.org/pep-0387/).
*exception* PendingDeprecationWarning[¶](#PendingDeprecationWarning "Link to this definition")
: Base class for warnings about features which are obsolete and
expected to be deprecated in the future, b... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
a344683a-05d3-595c-8d69-cb0dceebdc4f | docs | python | python_exceptions | 313 | 42 | This warning is typically emitted when compiling Python source code, and usually won’t be reported
when running already compiled code.
*exception* RuntimeWarning[¶](#RuntimeWarning "Link to this definition")
: Base class for warnings about dubious runtime behavior.
*exception* FutureWarning[¶](#FutureWarnin... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
4a84c711-b858-5513-8836-aadfec52c6cd | docs | python | python_exceptions | 313 | 43 | See [Opt-in EncodingWarning](io.html#io-encoding-warning) for details.
Added in version 3.10.
*exception* BytesWarning[¶](#BytesWarning "Link to this definition")
: Base class for warnings related to [`bytes`](stdtypes.html#bytes "bytes") and [`bytearray`](stdtypes.html#bytearray "bytearray").
*exception* ... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
48c5459d-0b2f-5a17-9640-4769b3f78cf2 | docs | python | python_exceptions | 313 | 44 | their subgroups based on the types of the contained exceptions.
*exception* ExceptionGroup(*msg*, *excs*)[¶](#ExceptionGroup "Link to this definition")
*exception* BaseExceptionGroup(*msg*, *excs*)[¶](#BaseExceptionGroup "Link to this definition")
: Both of these exception types wrap the exceptions in the sequence ... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
5770e172-450e-527a-994c-18f72cd0c477 | docs | python | python_exceptions | 313 | 45 | The [`BaseExceptionGroup`](#BaseExceptionGroup "BaseExceptionGroup") constructor returns an [`ExceptionGroup`](#ExceptionGroup "ExceptionGroup")
rather than a [`BaseExceptionGroup`](#BaseExceptionGroup "BaseExceptionGroup") if all contained exceptions are
[`Exception`](#Exception "Exception") instances, so ... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
a2e42278-dcec-582a-afbb-1d25b4048480 | docs | python | python_exceptions | 313 | 46 | exceptions[¶](#BaseExceptionGroup.exceptions "Link to this definition")
: A tuple of the exceptions in the `excs` sequence given to the
constructor. This is a read-only attribute.
subgroup(*condition*)[¶](#BaseExceptionGroup.subgroup "Link to this definition")
: Returns an exception group t... | large_dataset/raw/docs/python/exceptions/exceptions_313.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.