summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/library%2Fexceptions.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/python~3.12/library%2Fexceptions.html')
-rw-r--r--devdocs/python~3.12/library%2Fexceptions.html413
1 files changed, 413 insertions, 0 deletions
diff --git a/devdocs/python~3.12/library%2Fexceptions.html b/devdocs/python~3.12/library%2Fexceptions.html
new file mode 100644
index 00000000..257a7b9c
--- /dev/null
+++ b/devdocs/python~3.12/library%2Fexceptions.html
@@ -0,0 +1,413 @@
+ <span id="bltin-exceptions"></span><h1>Built-in Exceptions</h1> <p id="index-0">In Python, all exceptions must be instances of a class that derives from <a class="reference internal" href="#BaseException" title="BaseException"><code>BaseException</code></a>. In a <a class="reference internal" href="../reference/compound_stmts#try"><code>try</code></a> statement with an <a class="reference internal" href="../reference/compound_stmts#except"><code>except</code></a> clause that mentions a particular class, that clause also handles any exception classes derived from that class (but not exception classes from which <em>it</em> is derived). Two exception classes that are not related via subclassing are never equivalent, even if they have the same name.</p> <p id="index-1">The built-in exceptions listed below can be generated by the interpreter or built-in functions. Except where mentioned, they have an “associated value” indicating the detailed cause of the error. This may be a string or a tuple of several items of information (e.g., an error code and a string explaining the code). The associated value is usually passed as arguments to the exception class’s constructor.</p> <p>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.</p> <p>The built-in exception classes can be subclassed to define new exceptions; programmers are encouraged to derive new exceptions from the <a class="reference internal" href="#Exception" title="Exception"><code>Exception</code></a> class or one of its subclasses, and not from <a class="reference internal" href="#BaseException" title="BaseException"><code>BaseException</code></a>. More information on defining exceptions is available in the Python Tutorial under <a class="reference internal" href="../tutorial/errors#tut-userexceptions"><span class="std std-ref">User-defined Exceptions</span></a>.</p> <section id="exception-context"> <h2>Exception context</h2> <p id="index-2">Three attributes on exception objects provide information about the context in which the exception was raised:</p> <dl class="py attribute"> <dt class="sig sig-object py" id="BaseException.__context__">
+<code>BaseException.__context__</code> </dt> <dt class="sig sig-object py" id="BaseException.__cause__">
+<code>BaseException.__cause__</code> </dt> <dt class="sig sig-object py" id="BaseException.__suppress_context__">
+<code>BaseException.__suppress_context__</code> </dt> <dd>
+<p>When raising a new exception while another exception is already being handled, the new exception’s <code>__context__</code> attribute is automatically set to the handled exception. An exception may be handled when an <a class="reference internal" href="../reference/compound_stmts#except"><code>except</code></a> or <a class="reference internal" href="../reference/compound_stmts#finally"><code>finally</code></a> clause, or a <a class="reference internal" href="../reference/compound_stmts#with"><code>with</code></a> statement, is used.</p> <p>This implicit exception context can be supplemented with an explicit cause by using <code>from</code> with <a class="reference internal" href="../reference/simple_stmts#raise"><code>raise</code></a>:</p> <pre data-language="python">raise new_exc from original_exc
+</pre> <p>The expression following <a class="reference internal" href="../reference/simple_stmts#raise"><code>from</code></a> must be an exception or <code>None</code>. It will be set as <code>__cause__</code> on the raised exception. Setting <code>__cause__</code> also implicitly sets the <code>__suppress_context__</code> attribute to <code>True</code>, so that using <code>raise new_exc from None</code> effectively replaces the old exception with the new one for display purposes (e.g. converting <a class="reference internal" href="#KeyError" title="KeyError"><code>KeyError</code></a> to <a class="reference internal" href="#AttributeError" title="AttributeError"><code>AttributeError</code></a>), while leaving the old exception available in <code>__context__</code> for introspection when debugging.</p> <p>The default traceback display code shows these chained exceptions in addition to the traceback for the exception itself. An explicitly chained exception in <code>__cause__</code> is always shown when present. An implicitly chained exception in <code>__context__</code> is shown only if <code>__cause__</code> is <a class="reference internal" href="constants#None" title="None"><code>None</code></a> and <code>__suppress_context__</code> is false.</p> <p>In either case, the exception itself is always shown after any chained exceptions so that the final line of the traceback always shows the last exception that was raised.</p> </dd>
+</dl> </section> <section id="inheriting-from-built-in-exceptions"> <h2>Inheriting from built-in exceptions</h2> <p>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 <code>args</code> attribute, as well as due to possible memory layout incompatibilities.</p> <div class="impl-detail compound"> <p><strong>CPython implementation detail:</strong> Most built-in exceptions are implemented in C for efficiency, see: <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Objects/exceptions.c">Objects/exceptions.c</a>. Some have custom memory layouts which makes it impossible to create a subclass that inherits from multiple exception types. The memory layout of a type is an implementation detail and might change between Python versions, leading to new conflicts in the future. Therefore, it’s recommended to avoid subclassing multiple exception types altogether.</p> </div> </section> <section id="base-classes"> <h2>Base classes</h2> <p>The following exceptions are used mostly as base classes for other exceptions.</p> <dl class="py exception"> <dt class="sig sig-object py" id="BaseException">
+<code>exception BaseException</code> </dt> <dd>
+<p>The base class for all built-in exceptions. It is not meant to be directly inherited by user-defined classes (for that, use <a class="reference internal" href="#Exception" title="Exception"><code>Exception</code></a>). If <a class="reference internal" href="stdtypes#str" title="str"><code>str()</code></a> is called on an instance of this class, the representation of the argument(s) to the instance are returned, or the empty string when there were no arguments.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="BaseException.args">
+<code>args</code> </dt> <dd>
+<p>The tuple of arguments given to the exception constructor. Some built-in exceptions (like <a class="reference internal" href="#OSError" title="OSError"><code>OSError</code></a>) expect a certain number of arguments and assign a special meaning to the elements of this tuple, while others are usually called only with a single string giving an error message.</p> </dd>
+</dl> <dl class="py method"> <dt class="sig sig-object py" id="BaseException.with_traceback">
+<code>with_traceback(tb)</code> </dt> <dd>
+<p>This method sets <em>tb</em> as the new traceback for the exception and returns the exception object. It was more commonly used before the exception chaining features of <span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-3134/"><strong>PEP 3134</strong></a> became available. The following example shows how we can convert an instance of <code>SomeException</code> into an instance of <code>OtherException</code> while preserving the traceback. Once raised, the current frame is pushed onto the traceback of the <code>OtherException</code>, as would have happened to the traceback of the original <code>SomeException</code> had we allowed it to propagate to the caller.</p> <pre data-language="python">try:
+ ...
+except SomeException:
+ tb = sys.exception().__traceback__
+ raise OtherException(...).with_traceback(tb)
+</pre> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="BaseException.__traceback__">
+<code>__traceback__</code> </dt> <dd>
+<p>A writable field that holds the <a class="reference internal" href="../reference/datamodel#traceback-objects"><span class="std std-ref">traceback object</span></a> associated with this exception. See also: <a class="reference internal" href="../reference/simple_stmts#raise"><span class="std std-ref">The raise statement</span></a>.</p> </dd>
+</dl> <dl class="py method"> <dt class="sig sig-object py" id="BaseException.add_note">
+<code>add_note(note)</code> </dt> <dd>
+<p>Add the string <code>note</code> to the exception’s notes which appear in the standard traceback after the exception string. A <a class="reference internal" href="#TypeError" title="TypeError"><code>TypeError</code></a> is raised if <code>note</code> is not a string.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="BaseException.__notes__">
+<code>__notes__</code> </dt> <dd>
+<p>A list of the notes of this exception, which were added with <a class="reference internal" href="#BaseException.add_note" title="BaseException.add_note"><code>add_note()</code></a>. This attribute is created when <a class="reference internal" href="#BaseException.add_note" title="BaseException.add_note"><code>add_note()</code></a> is called.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd>
+</dl> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="Exception">
+<code>exception Exception</code> </dt> <dd>
+<p>All built-in, non-system-exiting exceptions are derived from this class. All user-defined exceptions should also be derived from this class.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ArithmeticError">
+<code>exception ArithmeticError</code> </dt> <dd>
+<p>The base class for those built-in exceptions that are raised for various arithmetic errors: <a class="reference internal" href="#OverflowError" title="OverflowError"><code>OverflowError</code></a>, <a class="reference internal" href="#ZeroDivisionError" title="ZeroDivisionError"><code>ZeroDivisionError</code></a>, <a class="reference internal" href="#FloatingPointError" title="FloatingPointError"><code>FloatingPointError</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="BufferError">
+<code>exception BufferError</code> </dt> <dd>
+<p>Raised when a <a class="reference internal" href="../c-api/buffer#bufferobjects"><span class="std std-ref">buffer</span></a> related operation cannot be performed.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="LookupError">
+<code>exception LookupError</code> </dt> <dd>
+<p>The base class for the exceptions that are raised when a key or index used on a mapping or sequence is invalid: <a class="reference internal" href="#IndexError" title="IndexError"><code>IndexError</code></a>, <a class="reference internal" href="#KeyError" title="KeyError"><code>KeyError</code></a>. This can be raised directly by <a class="reference internal" href="codecs#codecs.lookup" title="codecs.lookup"><code>codecs.lookup()</code></a>.</p> </dd>
+</dl> </section> <section id="concrete-exceptions"> <h2>Concrete exceptions</h2> <p>The following exceptions are the exceptions that are usually raised.</p> <dl class="py exception"> <dt class="sig sig-object py" id="AssertionError">
+<code>exception AssertionError</code> </dt> <dd>
+<p id="index-4">Raised when an <a class="reference internal" href="../reference/simple_stmts#assert"><code>assert</code></a> statement fails.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="AttributeError">
+<code>exception AttributeError</code> </dt> <dd>
+<p>Raised when an attribute reference (see <a class="reference internal" href="../reference/expressions#attribute-references"><span class="std std-ref">Attribute references</span></a>) or assignment fails. (When an object does not support attribute references or attribute assignments at all, <a class="reference internal" href="#TypeError" title="TypeError"><code>TypeError</code></a> is raised.)</p> <p>The <code>name</code> and <code>obj</code> attributes can be set using keyword-only arguments to the constructor. When set they represent the name of the attribute that was attempted to be accessed and the object that was accessed for said attribute, respectively.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.10: </span>Added the <code>name</code> and <code>obj</code> attributes.</p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="EOFError">
+<code>exception EOFError</code> </dt> <dd>
+<p>Raised when the <a class="reference internal" href="functions#input" title="input"><code>input()</code></a> function hits an end-of-file condition (EOF) without reading any data. (N.B.: the <code>io.IOBase.read()</code> and <a class="reference internal" href="io#io.IOBase.readline" title="io.IOBase.readline"><code>io.IOBase.readline()</code></a> methods return an empty string when they hit EOF.)</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="FloatingPointError">
+<code>exception FloatingPointError</code> </dt> <dd>
+<p>Not currently used.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="GeneratorExit">
+<code>exception GeneratorExit</code> </dt> <dd>
+<p>Raised when a <a class="reference internal" href="../glossary#term-generator"><span class="xref std std-term">generator</span></a> or <a class="reference internal" href="../glossary#term-coroutine"><span class="xref std std-term">coroutine</span></a> is closed; see <a class="reference internal" href="../reference/expressions#generator.close" title="generator.close"><code>generator.close()</code></a> and <a class="reference internal" href="../reference/datamodel#coroutine.close" title="coroutine.close"><code>coroutine.close()</code></a>. It directly inherits from <a class="reference internal" href="#BaseException" title="BaseException"><code>BaseException</code></a> instead of <a class="reference internal" href="#Exception" title="Exception"><code>Exception</code></a> since it is technically not an error.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ImportError">
+<code>exception ImportError</code> </dt> <dd>
+<p>Raised when the <a class="reference internal" href="../reference/simple_stmts#import"><code>import</code></a> statement has troubles trying to load a module. Also raised when the “from list” in <code>from ... import</code> has a name that cannot be found.</p> <p>The optional <em>name</em> and <em>path</em> keyword-only arguments set the corresponding attributes:</p> <dl class="py attribute"> <dt class="sig sig-object py" id="ImportError.name">
+<code>name</code> </dt> <dd>
+<p>The name of the module that was attempted to be imported.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="ImportError.path">
+<code>path</code> </dt> <dd>
+<p>The path to any file which triggered the exception.</p> </dd>
+</dl> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <a class="reference internal" href="#ImportError.name" title="ImportError.name"><code>name</code></a> and <a class="reference internal" href="#ImportError.path" title="ImportError.path"><code>path</code></a> attributes.</p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ModuleNotFoundError">
+<code>exception ModuleNotFoundError</code> </dt> <dd>
+<p>A subclass of <a class="reference internal" href="#ImportError" title="ImportError"><code>ImportError</code></a> which is raised by <a class="reference internal" href="../reference/simple_stmts#import"><code>import</code></a> when a module could not be located. It is also raised when <code>None</code> is found in <a class="reference internal" href="sys#sys.modules" title="sys.modules"><code>sys.modules</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.6.</span></p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="IndexError">
+<code>exception IndexError</code> </dt> <dd>
+<p>Raised when a sequence subscript is out of range. (Slice indices are silently truncated to fall in the allowed range; if an index is not an integer, <a class="reference internal" href="#TypeError" title="TypeError"><code>TypeError</code></a> is raised.)</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="KeyError">
+<code>exception KeyError</code> </dt> <dd>
+<p>Raised when a mapping (dictionary) key is not found in the set of existing keys.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="KeyboardInterrupt">
+<code>exception KeyboardInterrupt</code> </dt> <dd>
+<p>Raised when the user hits the interrupt key (normally <kbd class="kbd compound docutils literal notranslate"><kbd class="kbd docutils literal notranslate">Control</kbd>-<kbd class="kbd docutils literal notranslate">C</kbd></kbd> or <kbd class="kbd docutils literal notranslate">Delete</kbd>). During execution, a check for interrupts is made regularly. The exception inherits from <a class="reference internal" href="#BaseException" title="BaseException"><code>BaseException</code></a> so as to not be accidentally caught by code that catches <a class="reference internal" href="#Exception" title="Exception"><code>Exception</code></a> and thus prevent the interpreter from exiting.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>Catching a <a class="reference internal" href="#KeyboardInterrupt" title="KeyboardInterrupt"><code>KeyboardInterrupt</code></a> requires special consideration. Because it can be raised at unpredictable points, it may, in some circumstances, leave the running program in an inconsistent state. It is generally best to allow <a class="reference internal" href="#KeyboardInterrupt" title="KeyboardInterrupt"><code>KeyboardInterrupt</code></a> to end the program as quickly as possible or avoid raising it entirely. (See <a class="reference internal" href="signal#handlers-and-exceptions"><span class="std std-ref">Note on Signal Handlers and Exceptions</span></a>.)</p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="MemoryError">
+<code>exception MemoryError</code> </dt> <dd>
+<p>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 underlying memory management architecture (C’s <code>malloc()</code> 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 printed, in case a run-away program was the cause.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="NameError">
+<code>exception NameError</code> </dt> <dd>
+<p>Raised when a local or global name is not found. This applies only to unqualified names. The associated value is an error message that includes the name that could not be found.</p> <p>The <code>name</code> attribute can be set using a keyword-only argument to the constructor. When set it represent the name of the variable that was attempted to be accessed.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.10: </span>Added the <code>name</code> attribute.</p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="NotImplementedError">
+<code>exception NotImplementedError</code> </dt> <dd>
+<p>This exception is derived from <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code>RuntimeError</code></a>. 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 to be added.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>It should not be used to indicate that an operator or method is not meant to be supported at all – in that case either leave the operator / method undefined or, if a subclass, set it to <a class="reference internal" href="constants#None" title="None"><code>None</code></a>.</p> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <p><code>NotImplementedError</code> and <code>NotImplemented</code> are not interchangeable, even though they have similar names and purposes. See <a class="reference internal" href="constants#NotImplemented" title="NotImplemented"><code>NotImplemented</code></a> for details on when to use it.</p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="OSError">
+<code>exception OSError([arg])</code> </dt> <dt class="sig sig-object py"> <em class="property">exception<span class="w"> </span></em><span class="sig-name descname">OSError</span><span class="sig-paren">(</span><em class="sig-param"><span class="n">errno</span></em>, <em class="sig-param"><span class="n">strerror</span></em><span class="optional">[</span>, <em class="sig-param"><span class="n">filename</span></em><span class="optional">[</span>, <em class="sig-param"><span class="n">winerror</span></em><span class="optional">[</span>, <em class="sig-param"><span class="n">filename2</span></em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span>
+</dt> <dd>
+<p id="index-5">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).</p> <p>The second form of the constructor sets the corresponding attributes, described below. The attributes default to <a class="reference internal" href="constants#None" title="None"><code>None</code></a> if not specified. For backwards compatibility, if three arguments are passed, the <a class="reference internal" href="#BaseException.args" title="BaseException.args"><code>args</code></a> attribute contains only a 2-tuple of the first two constructor arguments.</p> <p>The constructor often actually returns a subclass of <a class="reference internal" href="#OSError" title="OSError"><code>OSError</code></a>, as described in <a class="reference internal" href="#os-exceptions">OS exceptions</a> below. The particular subclass depends on the final <a class="reference internal" href="#OSError.errno" title="OSError.errno"><code>errno</code></a> value. This behaviour only occurs when constructing <a class="reference internal" href="#OSError" title="OSError"><code>OSError</code></a> directly or via an alias, and is not inherited when subclassing.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="OSError.errno">
+<code>errno</code> </dt> <dd>
+<p>A numeric error code from the C variable <code>errno</code>.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="OSError.winerror">
+<code>winerror</code> </dt> <dd>
+<p>Under Windows, this gives you the native Windows error code. The <a class="reference internal" href="#OSError.errno" title="OSError.errno"><code>errno</code></a> attribute is then an approximate translation, in POSIX terms, of that native error code.</p> <p>Under Windows, if the <em>winerror</em> constructor argument is an integer, the <a class="reference internal" href="#OSError.errno" title="OSError.errno"><code>errno</code></a> attribute is determined from the Windows error code, and the <em>errno</em> argument is ignored. On other platforms, the <em>winerror</em> argument is ignored, and the <a class="reference internal" href="#OSError.winerror" title="OSError.winerror"><code>winerror</code></a> attribute does not exist.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="OSError.strerror">
+<code>strerror</code> </dt> <dd>
+<p>The corresponding error message, as provided by the operating system. It is formatted by the C functions <code>perror()</code> under POSIX, and <code>FormatMessage()</code> under Windows.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="OSError.filename">
+<code>filename</code> </dt> <dt class="sig sig-object py" id="OSError.filename2">
+<code>filename2</code> </dt> <dd>
+<p>For exceptions that involve a file system path (such as <a class="reference internal" href="functions#open" title="open"><code>open()</code></a> or <a class="reference internal" href="os#os.unlink" title="os.unlink"><code>os.unlink()</code></a>), <a class="reference internal" href="#OSError.filename" title="OSError.filename"><code>filename</code></a> is the file name passed to the function. For functions that involve two file system paths (such as <a class="reference internal" href="os#os.rename" title="os.rename"><code>os.rename()</code></a>), <a class="reference internal" href="#OSError.filename2" title="OSError.filename2"><code>filename2</code></a> corresponds to the second file name passed to the function.</p> </dd>
+</dl> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.3: </span><a class="reference internal" href="#EnvironmentError" title="EnvironmentError"><code>EnvironmentError</code></a>, <a class="reference internal" href="#IOError" title="IOError"><code>IOError</code></a>, <a class="reference internal" href="#WindowsError" title="WindowsError"><code>WindowsError</code></a>, <a class="reference internal" href="socket#socket.error" title="socket.error"><code>socket.error</code></a>, <a class="reference internal" href="select#select.error" title="select.error"><code>select.error</code></a> and <code>mmap.error</code> have been merged into <a class="reference internal" href="#OSError" title="OSError"><code>OSError</code></a>, and the constructor may return a subclass.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.4: </span>The <a class="reference internal" href="#OSError.filename" title="OSError.filename"><code>filename</code></a> attribute is now the original file name passed to the function, instead of the name encoded to or decoded from the <a class="reference internal" href="../glossary#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>. Also, the <em>filename2</em> constructor argument and attribute was added.</p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="OverflowError">
+<code>exception OverflowError</code> </dt> <dd>
+<p>Raised when the result of an arithmetic operation is too large to be represented. This cannot occur for integers (which would rather raise <a class="reference internal" href="#MemoryError" title="MemoryError"><code>MemoryError</code></a> 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.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="RecursionError">
+<code>exception RecursionError</code> </dt> <dd>
+<p>This exception is derived from <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code>RuntimeError</code></a>. It is raised when the interpreter detects that the maximum recursion depth (see <a class="reference internal" href="sys#sys.getrecursionlimit" title="sys.getrecursionlimit"><code>sys.getrecursionlimit()</code></a>) is exceeded.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5: </span>Previously, a plain <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code>RuntimeError</code></a> was raised.</p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ReferenceError">
+<code>exception ReferenceError</code> </dt> <dd>
+<p>This exception is raised when a weak reference proxy, created by the <a class="reference internal" href="weakref#weakref.proxy" title="weakref.proxy"><code>weakref.proxy()</code></a> function, is used to access an attribute of the referent after it has been garbage collected. For more information on weak references, see the <a class="reference internal" href="weakref#module-weakref" title="weakref: Support for weak references and weak dictionaries."><code>weakref</code></a> module.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="RuntimeError">
+<code>exception RuntimeError</code> </dt> <dd>
+<p>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.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="StopIteration">
+<code>exception StopIteration</code> </dt> <dd>
+<p>Raised by built-in function <a class="reference internal" href="functions#next" title="next"><code>next()</code></a> and an <a class="reference internal" href="../glossary#term-iterator"><span class="xref std std-term">iterator</span></a>'s <a class="reference internal" href="stdtypes#iterator.__next__" title="iterator.__next__"><code>__next__()</code></a> method to signal that there are no further items produced by the iterator.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="StopIteration.value">
+<code>value</code> </dt> <dd>
+<p>The exception object has a single attribute <code>value</code>, which is given as an argument when constructing the exception, and defaults to <a class="reference internal" href="constants#None" title="None"><code>None</code></a>.</p> </dd>
+</dl> <p>When a <a class="reference internal" href="../glossary#term-generator"><span class="xref std std-term">generator</span></a> or <a class="reference internal" href="../glossary#term-coroutine"><span class="xref std std-term">coroutine</span></a> function returns, a new <a class="reference internal" href="#StopIteration" title="StopIteration"><code>StopIteration</code></a> instance is raised, and the value returned by the function is used as the <a class="reference internal" href="#StopIteration.value" title="StopIteration.value"><code>value</code></a> parameter to the constructor of the exception.</p> <p>If a generator code directly or indirectly raises <a class="reference internal" href="#StopIteration" title="StopIteration"><code>StopIteration</code></a>, it is converted into a <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code>RuntimeError</code></a> (retaining the <a class="reference internal" href="#StopIteration" title="StopIteration"><code>StopIteration</code></a> as the new exception’s cause).</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.3: </span>Added <code>value</code> attribute and the ability for generator functions to use it to return a value.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.5: </span>Introduced the RuntimeError transformation via <code>from __future__ import generator_stop</code>, see <span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0479/"><strong>PEP 479</strong></a>.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.7: </span>Enable <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0479/"><strong>PEP 479</strong></a> for all code by default: a <a class="reference internal" href="#StopIteration" title="StopIteration"><code>StopIteration</code></a> error raised in a generator is transformed into a <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code>RuntimeError</code></a>.</p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="StopAsyncIteration">
+<code>exception StopAsyncIteration</code> </dt> <dd>
+<p>Must be raised by <a class="reference internal" href="../reference/datamodel#object.__anext__" title="object.__anext__"><code>__anext__()</code></a> method of an <a class="reference internal" href="../glossary#term-asynchronous-iterator"><span class="xref std std-term">asynchronous iterator</span></a> object to stop the iteration.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="SyntaxError">
+<code>exception SyntaxError(message, details)</code> </dt> <dd>
+<p>Raised when the parser encounters a syntax error. This may occur in an <a class="reference internal" href="../reference/simple_stmts#import"><code>import</code></a> statement, in a call to the built-in functions <a class="reference internal" href="functions#compile" title="compile"><code>compile()</code></a>, <a class="reference internal" href="functions#exec" title="exec"><code>exec()</code></a>, or <a class="reference internal" href="functions#eval" title="eval"><code>eval()</code></a>, or when reading the initial script or standard input (also interactively).</p> <p>The <a class="reference internal" href="stdtypes#str" title="str"><code>str()</code></a> of the exception instance returns only the error message. Details is a tuple whose members are also available as separate attributes.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="SyntaxError.filename">
+<code>filename</code> </dt> <dd>
+<p>The name of the file the syntax error occurred in.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="SyntaxError.lineno">
+<code>lineno</code> </dt> <dd>
+<p>Which line number in the file the error occurred in. This is 1-indexed: the first line in the file has a <code>lineno</code> of 1.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="SyntaxError.offset">
+<code>offset</code> </dt> <dd>
+<p>The column in the line where the error occurred. This is 1-indexed: the first character in the line has an <code>offset</code> of 1.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="SyntaxError.text">
+<code>text</code> </dt> <dd>
+<p>The source code text involved in the error.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="SyntaxError.end_lineno">
+<code>end_lineno</code> </dt> <dd>
+<p>Which line number in the file the error occurred ends in. This is 1-indexed: the first line in the file has a <code>lineno</code> of 1.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="SyntaxError.end_offset">
+<code>end_offset</code> </dt> <dd>
+<p>The column in the end line where the error occurred finishes. This is 1-indexed: the first character in the line has an <code>offset</code> of 1.</p> </dd>
+</dl> <p>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: (‘f-string: …’, (‘’, 1, 2, ‘(a b)n’, 1, 5)).</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.10: </span>Added the <a class="reference internal" href="#SyntaxError.end_lineno" title="SyntaxError.end_lineno"><code>end_lineno</code></a> and <a class="reference internal" href="#SyntaxError.end_offset" title="SyntaxError.end_offset"><code>end_offset</code></a> attributes.</p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="IndentationError">
+<code>exception IndentationError</code> </dt> <dd>
+<p>Base class for syntax errors related to incorrect indentation. This is a subclass of <a class="reference internal" href="#SyntaxError" title="SyntaxError"><code>SyntaxError</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="TabError">
+<code>exception TabError</code> </dt> <dd>
+<p>Raised when indentation contains an inconsistent use of tabs and spaces. This is a subclass of <a class="reference internal" href="#IndentationError" title="IndentationError"><code>IndentationError</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="SystemError">
+<code>exception SystemError</code> </dt> <dd>
+<p>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).</p> <p>You should report this to the author or maintainer of your Python interpreter. Be sure to report the version of the Python interpreter (<code>sys.version</code>; it is 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.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="SystemExit">
+<code>exception SystemExit</code> </dt> <dd>
+<p>This exception is raised by the <a class="reference internal" href="sys#sys.exit" title="sys.exit"><code>sys.exit()</code></a> function. It inherits from <a class="reference internal" href="#BaseException" title="BaseException"><code>BaseException</code></a> instead of <a class="reference internal" href="#Exception" title="Exception"><code>Exception</code></a> so that it is not accidentally caught by code that catches <a class="reference internal" href="#Exception" title="Exception"><code>Exception</code></a>. This allows the exception to properly propagate up and cause the interpreter to exit. When it is not handled, the Python interpreter exits; no stack traceback is printed. The constructor accepts the same optional argument passed to <a class="reference internal" href="sys#sys.exit" title="sys.exit"><code>sys.exit()</code></a>. If the value is an integer, it specifies the system exit status (passed to C’s <code>exit()</code> function); if it is <code>None</code>, the exit status is zero; if it has another type (such as a string), the object’s value is printed and the exit status is one.</p> <p>A call to <a class="reference internal" href="sys#sys.exit" title="sys.exit"><code>sys.exit()</code></a> is translated into an exception so that clean-up handlers (<a class="reference internal" href="../reference/compound_stmts#finally"><code>finally</code></a> clauses of <a class="reference internal" href="../reference/compound_stmts#try"><code>try</code></a> statements) can be executed, and so that a debugger can execute a script without running the risk of losing control. The <a class="reference internal" href="os#os._exit" title="os._exit"><code>os._exit()</code></a> function can be used if it is absolutely positively necessary to exit immediately (for example, in the child process after a call to <a class="reference internal" href="os#os.fork" title="os.fork"><code>os.fork()</code></a>).</p> <dl class="py attribute"> <dt class="sig sig-object py" id="SystemExit.code">
+<code>code</code> </dt> <dd>
+<p>The exit status or error message that is passed to the constructor. (Defaults to <code>None</code>.)</p> </dd>
+</dl> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="TypeError">
+<code>exception TypeError</code> </dt> <dd>
+<p>Raised when an operation or function is applied to an object of inappropriate type. The associated value is a string giving details about the type mismatch.</p> <p>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 implementation, <a class="reference internal" href="#NotImplementedError" title="NotImplementedError"><code>NotImplementedError</code></a> is the proper exception to raise.</p> <p>Passing arguments of the wrong type (e.g. passing a <a class="reference internal" href="stdtypes#list" title="list"><code>list</code></a> when an <a class="reference internal" href="functions#int" title="int"><code>int</code></a> is expected) should result in a <a class="reference internal" href="#TypeError" title="TypeError"><code>TypeError</code></a>, but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a <a class="reference internal" href="#ValueError" title="ValueError"><code>ValueError</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="UnboundLocalError">
+<code>exception UnboundLocalError</code> </dt> <dd>
+<p>Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variable. This is a subclass of <a class="reference internal" href="#NameError" title="NameError"><code>NameError</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="UnicodeError">
+<code>exception UnicodeError</code> </dt> <dd>
+<p>Raised when a Unicode-related encoding or decoding error occurs. It is a subclass of <a class="reference internal" href="#ValueError" title="ValueError"><code>ValueError</code></a>.</p> <p><a class="reference internal" href="#UnicodeError" title="UnicodeError"><code>UnicodeError</code></a> has attributes that describe the encoding or decoding error. For example, <code>err.object[err.start:err.end]</code> gives the particular invalid input that the codec failed on.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="UnicodeError.encoding">
+<code>encoding</code> </dt> <dd>
+<p>The name of the encoding that raised the error.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="UnicodeError.reason">
+<code>reason</code> </dt> <dd>
+<p>A string describing the specific codec error.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="UnicodeError.object">
+<code>object</code> </dt> <dd>
+<p>The object the codec was attempting to encode or decode.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="UnicodeError.start">
+<code>start</code> </dt> <dd>
+<p>The first index of invalid data in <a class="reference internal" href="functions#object" title="object"><code>object</code></a>.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="UnicodeError.end">
+<code>end</code> </dt> <dd>
+<p>The index after the last invalid data in <a class="reference internal" href="functions#object" title="object"><code>object</code></a>.</p> </dd>
+</dl> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="UnicodeEncodeError">
+<code>exception UnicodeEncodeError</code> </dt> <dd>
+<p>Raised when a Unicode-related error occurs during encoding. It is a subclass of <a class="reference internal" href="#UnicodeError" title="UnicodeError"><code>UnicodeError</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="UnicodeDecodeError">
+<code>exception UnicodeDecodeError</code> </dt> <dd>
+<p>Raised when a Unicode-related error occurs during decoding. It is a subclass of <a class="reference internal" href="#UnicodeError" title="UnicodeError"><code>UnicodeError</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="UnicodeTranslateError">
+<code>exception UnicodeTranslateError</code> </dt> <dd>
+<p>Raised when a Unicode-related error occurs during translating. It is a subclass of <a class="reference internal" href="#UnicodeError" title="UnicodeError"><code>UnicodeError</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ValueError">
+<code>exception ValueError</code> </dt> <dd>
+<p>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 <a class="reference internal" href="#IndexError" title="IndexError"><code>IndexError</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ZeroDivisionError">
+<code>exception ZeroDivisionError</code> </dt> <dd>
+<p>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 operation.</p> </dd>
+</dl> <p>The following exceptions are kept for compatibility with previous versions; starting from Python 3.3, they are aliases of <a class="reference internal" href="#OSError" title="OSError"><code>OSError</code></a>.</p> <dl class="py exception"> <dt class="sig sig-object py" id="EnvironmentError">
+<code>exception EnvironmentError</code> </dt> <dd></dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="IOError">
+<code>exception IOError</code> </dt> <dd></dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="WindowsError">
+<code>exception WindowsError</code> </dt> <dd>
+<p>Only available on Windows.</p> </dd>
+</dl> <section id="os-exceptions"> <h3>OS exceptions</h3> <p>The following exceptions are subclasses of <a class="reference internal" href="#OSError" title="OSError"><code>OSError</code></a>, they get raised depending on the system error code.</p> <dl class="py exception"> <dt class="sig sig-object py" id="BlockingIOError">
+<code>exception BlockingIOError</code> </dt> <dd>
+<p>Raised when an operation would block on an object (e.g. socket) set for non-blocking operation. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.EAGAIN" title="errno.EAGAIN"><code>EAGAIN</code></a>, <a class="reference internal" href="errno#errno.EALREADY" title="errno.EALREADY"><code>EALREADY</code></a>, <a class="reference internal" href="errno#errno.EWOULDBLOCK" title="errno.EWOULDBLOCK"><code>EWOULDBLOCK</code></a> and <a class="reference internal" href="errno#errno.EINPROGRESS" title="errno.EINPROGRESS"><code>EINPROGRESS</code></a>.</p> <p>In addition to those of <a class="reference internal" href="#OSError" title="OSError"><code>OSError</code></a>, <a class="reference internal" href="#BlockingIOError" title="BlockingIOError"><code>BlockingIOError</code></a> can have one more attribute:</p> <dl class="py attribute"> <dt class="sig sig-object py" id="BlockingIOError.characters_written">
+<code>characters_written</code> </dt> <dd>
+<p>An integer containing the number of characters written to the stream before it blocked. This attribute is available when using the buffered I/O classes from the <a class="reference internal" href="io#module-io" title="io: Core tools for working with streams."><code>io</code></a> module.</p> </dd>
+</dl> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ChildProcessError">
+<code>exception ChildProcessError</code> </dt> <dd>
+<p>Raised when an operation on a child process failed. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.ECHILD" title="errno.ECHILD"><code>ECHILD</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ConnectionError">
+<code>exception ConnectionError</code> </dt> <dd>
+<p>A base class for connection-related issues.</p> <p>Subclasses are <a class="reference internal" href="#BrokenPipeError" title="BrokenPipeError"><code>BrokenPipeError</code></a>, <a class="reference internal" href="#ConnectionAbortedError" title="ConnectionAbortedError"><code>ConnectionAbortedError</code></a>, <a class="reference internal" href="#ConnectionRefusedError" title="ConnectionRefusedError"><code>ConnectionRefusedError</code></a> and <a class="reference internal" href="#ConnectionResetError" title="ConnectionResetError"><code>ConnectionResetError</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="BrokenPipeError">
+<code>exception BrokenPipeError</code> </dt> <dd>
+<p>A subclass of <a class="reference internal" href="#ConnectionError" title="ConnectionError"><code>ConnectionError</code></a>, raised when trying to write on a pipe while the other end has been closed, or trying to write on a socket which has been shutdown for writing. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.EPIPE" title="errno.EPIPE"><code>EPIPE</code></a> and <a class="reference internal" href="errno#errno.ESHUTDOWN" title="errno.ESHUTDOWN"><code>ESHUTDOWN</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ConnectionAbortedError">
+<code>exception ConnectionAbortedError</code> </dt> <dd>
+<p>A subclass of <a class="reference internal" href="#ConnectionError" title="ConnectionError"><code>ConnectionError</code></a>, raised when a connection attempt is aborted by the peer. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.ECONNABORTED" title="errno.ECONNABORTED"><code>ECONNABORTED</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ConnectionRefusedError">
+<code>exception ConnectionRefusedError</code> </dt> <dd>
+<p>A subclass of <a class="reference internal" href="#ConnectionError" title="ConnectionError"><code>ConnectionError</code></a>, raised when a connection attempt is refused by the peer. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.ECONNREFUSED" title="errno.ECONNREFUSED"><code>ECONNREFUSED</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ConnectionResetError">
+<code>exception ConnectionResetError</code> </dt> <dd>
+<p>A subclass of <a class="reference internal" href="#ConnectionError" title="ConnectionError"><code>ConnectionError</code></a>, raised when a connection is reset by the peer. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.ECONNRESET" title="errno.ECONNRESET"><code>ECONNRESET</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="FileExistsError">
+<code>exception FileExistsError</code> </dt> <dd>
+<p>Raised when trying to create a file or directory which already exists. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.EEXIST" title="errno.EEXIST"><code>EEXIST</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="FileNotFoundError">
+<code>exception FileNotFoundError</code> </dt> <dd>
+<p>Raised when a file or directory is requested but doesn’t exist. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.ENOENT" title="errno.ENOENT"><code>ENOENT</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="InterruptedError">
+<code>exception InterruptedError</code> </dt> <dd>
+<p>Raised when a system call is interrupted by an incoming signal. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.EINTR" title="errno.EINTR"><code>EINTR</code></a>.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.5: </span>Python now retries system calls when a syscall is interrupted by a signal, except if the signal handler raises an exception (see <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> for the rationale), instead of raising <a class="reference internal" href="#InterruptedError" title="InterruptedError"><code>InterruptedError</code></a>.</p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="IsADirectoryError">
+<code>exception IsADirectoryError</code> </dt> <dd>
+<p>Raised when a file operation (such as <a class="reference internal" href="os#os.remove" title="os.remove"><code>os.remove()</code></a>) is requested on a directory. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.EISDIR" title="errno.EISDIR"><code>EISDIR</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="NotADirectoryError">
+<code>exception NotADirectoryError</code> </dt> <dd>
+<p>Raised when a directory operation (such as <a class="reference internal" href="os#os.listdir" title="os.listdir"><code>os.listdir()</code></a>) is requested on something which is not a directory. On most POSIX platforms, it may also be raised if an operation attempts to open or traverse a non-directory file as if it were a directory. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.ENOTDIR" title="errno.ENOTDIR"><code>ENOTDIR</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="PermissionError">
+<code>exception PermissionError</code> </dt> <dd>
+<p>Raised when trying to run an operation without the adequate access rights - for example filesystem permissions. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.EACCES" title="errno.EACCES"><code>EACCES</code></a>, <a class="reference internal" href="errno#errno.EPERM" title="errno.EPERM"><code>EPERM</code></a>, and <a class="reference internal" href="errno#errno.ENOTCAPABLE" title="errno.ENOTCAPABLE"><code>ENOTCAPABLE</code></a>.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.11.1: </span>WASI’s <a class="reference internal" href="errno#errno.ENOTCAPABLE" title="errno.ENOTCAPABLE"><code>ENOTCAPABLE</code></a> is now mapped to <a class="reference internal" href="#PermissionError" title="PermissionError"><code>PermissionError</code></a>.</p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ProcessLookupError">
+<code>exception ProcessLookupError</code> </dt> <dd>
+<p>Raised when a given process doesn’t exist. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.ESRCH" title="errno.ESRCH"><code>ESRCH</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="TimeoutError">
+<code>exception TimeoutError</code> </dt> <dd>
+<p>Raised when a system function timed out at the system level. Corresponds to <code>errno</code> <a class="reference internal" href="errno#errno.ETIMEDOUT" title="errno.ETIMEDOUT"><code>ETIMEDOUT</code></a>.</p> </dd>
+</dl> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.3: </span>All the above <a class="reference internal" href="#OSError" title="OSError"><code>OSError</code></a> subclasses were added.</p> </div> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-3151/"><strong>PEP 3151</strong></a> - Reworking the OS and IO exception hierarchy</p> </div> </section> </section> <section id="warnings"> <span id="warning-categories-as-exceptions"></span><h2>Warnings</h2> <p>The following exceptions are used as warning categories; see the <a class="reference internal" href="warnings#warning-categories"><span class="std std-ref">Warning Categories</span></a> documentation for more details.</p> <dl class="py exception"> <dt class="sig sig-object py" id="Warning">
+<code>exception Warning</code> </dt> <dd>
+<p>Base class for warning categories.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="UserWarning">
+<code>exception UserWarning</code> </dt> <dd>
+<p>Base class for warnings generated by user code.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="DeprecationWarning">
+<code>exception DeprecationWarning</code> </dt> <dd>
+<p>Base class for warnings about deprecated features when those warnings are intended for other Python developers.</p> <p>Ignored by the default warning filters, except in the <code>__main__</code> module (<span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0565/"><strong>PEP 565</strong></a>). Enabling the <a class="reference internal" href="devmode#devmode"><span class="std std-ref">Python Development Mode</span></a> shows this warning.</p> <p>The deprecation policy is described in <span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0387/"><strong>PEP 387</strong></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="PendingDeprecationWarning">
+<code>exception PendingDeprecationWarning</code> </dt> <dd>
+<p>Base class for warnings about features which are obsolete and expected to be deprecated in the future, but are not deprecated at the moment.</p> <p>This class is rarely used as emitting a warning about a possible upcoming deprecation is unusual, and <a class="reference internal" href="#DeprecationWarning" title="DeprecationWarning"><code>DeprecationWarning</code></a> is preferred for already active deprecations.</p> <p>Ignored by the default warning filters. Enabling the <a class="reference internal" href="devmode#devmode"><span class="std std-ref">Python Development Mode</span></a> shows this warning.</p> <p>The deprecation policy is described in <span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0387/"><strong>PEP 387</strong></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="SyntaxWarning">
+<code>exception SyntaxWarning</code> </dt> <dd>
+<p>Base class for warnings about dubious syntax.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="RuntimeWarning">
+<code>exception RuntimeWarning</code> </dt> <dd>
+<p>Base class for warnings about dubious runtime behavior.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="FutureWarning">
+<code>exception FutureWarning</code> </dt> <dd>
+<p>Base class for warnings about deprecated features when those warnings are intended for end users of applications that are written in Python.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ImportWarning">
+<code>exception ImportWarning</code> </dt> <dd>
+<p>Base class for warnings about probable mistakes in module imports.</p> <p>Ignored by the default warning filters. Enabling the <a class="reference internal" href="devmode#devmode"><span class="std std-ref">Python Development Mode</span></a> shows this warning.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="UnicodeWarning">
+<code>exception UnicodeWarning</code> </dt> <dd>
+<p>Base class for warnings related to Unicode.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="EncodingWarning">
+<code>exception EncodingWarning</code> </dt> <dd>
+<p>Base class for warnings related to encodings.</p> <p>See <a class="reference internal" href="io#io-encoding-warning"><span class="std std-ref">Opt-in EncodingWarning</span></a> for details.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.10.</span></p> </div> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="BytesWarning">
+<code>exception BytesWarning</code> </dt> <dd>
+<p>Base class for warnings related to <a class="reference internal" href="stdtypes#bytes" title="bytes"><code>bytes</code></a> and <a class="reference internal" href="stdtypes#bytearray" title="bytearray"><code>bytearray</code></a>.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="ResourceWarning">
+<code>exception ResourceWarning</code> </dt> <dd>
+<p>Base class for warnings related to resource usage.</p> <p>Ignored by the default warning filters. Enabling the <a class="reference internal" href="devmode#devmode"><span class="std std-ref">Python Development Mode</span></a> shows this warning.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd>
+</dl> </section> <section id="exception-groups"> <span id="lib-exception-groups"></span><h2>Exception groups</h2> <p>The following are used when it is necessary to raise multiple unrelated exceptions. They are part of the exception hierarchy so they can be handled with <a class="reference internal" href="../reference/compound_stmts#except"><code>except</code></a> like all other exceptions. In addition, they are recognised by <a class="reference internal" href="../reference/compound_stmts#except-star"><code>except*</code></a>, which matches their subgroups based on the types of the contained exceptions.</p> <dl class="py exception"> <dt class="sig sig-object py" id="ExceptionGroup">
+<code>exception ExceptionGroup(msg, excs)</code> </dt> <dd></dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="BaseExceptionGroup">
+<code>exception BaseExceptionGroup(msg, excs)</code> </dt> <dd>
+<p>Both of these exception types wrap the exceptions in the sequence <code>excs</code>. The <code>msg</code> parameter must be a string. The difference between the two classes is that <a class="reference internal" href="#BaseExceptionGroup" title="BaseExceptionGroup"><code>BaseExceptionGroup</code></a> extends <a class="reference internal" href="#BaseException" title="BaseException"><code>BaseException</code></a> and it can wrap any exception, while <a class="reference internal" href="#ExceptionGroup" title="ExceptionGroup"><code>ExceptionGroup</code></a> extends <a class="reference internal" href="#Exception" title="Exception"><code>Exception</code></a> and it can only wrap subclasses of <a class="reference internal" href="#Exception" title="Exception"><code>Exception</code></a>. This design is so that <code>except Exception</code> catches an <a class="reference internal" href="#ExceptionGroup" title="ExceptionGroup"><code>ExceptionGroup</code></a> but not <a class="reference internal" href="#BaseExceptionGroup" title="BaseExceptionGroup"><code>BaseExceptionGroup</code></a>.</p> <p>The <a class="reference internal" href="#BaseExceptionGroup" title="BaseExceptionGroup"><code>BaseExceptionGroup</code></a> constructor returns an <a class="reference internal" href="#ExceptionGroup" title="ExceptionGroup"><code>ExceptionGroup</code></a> rather than a <a class="reference internal" href="#BaseExceptionGroup" title="BaseExceptionGroup"><code>BaseExceptionGroup</code></a> if all contained exceptions are <a class="reference internal" href="#Exception" title="Exception"><code>Exception</code></a> instances, so it can be used to make the selection automatic. The <a class="reference internal" href="#ExceptionGroup" title="ExceptionGroup"><code>ExceptionGroup</code></a> constructor, on the other hand, raises a <a class="reference internal" href="#TypeError" title="TypeError"><code>TypeError</code></a> if any contained exception is not an <a class="reference internal" href="#Exception" title="Exception"><code>Exception</code></a> subclass.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="BaseExceptionGroup.message">
+<code>message</code> </dt> <dd>
+<p>The <code>msg</code> argument to the constructor. This is a read-only attribute.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="BaseExceptionGroup.exceptions">
+<code>exceptions</code> </dt> <dd>
+<p>A tuple of the exceptions in the <code>excs</code> sequence given to the constructor. This is a read-only attribute.</p> </dd>
+</dl> <dl class="py method"> <dt class="sig sig-object py" id="BaseExceptionGroup.subgroup">
+<code>subgroup(condition)</code> </dt> <dd>
+<p>Returns an exception group that contains only the exceptions from the current group that match <em>condition</em>, or <code>None</code> if the result is empty.</p> <p>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 match using the same check that is used in an <code>except</code> clause.</p> <p>The nesting structure of the current exception is preserved in the result, as are the values of its <a class="reference internal" href="#BaseExceptionGroup.message" title="BaseExceptionGroup.message"><code>message</code></a>, <a class="reference internal" href="#BaseException.__traceback__" title="BaseException.__traceback__"><code>__traceback__</code></a>, <a class="reference internal" href="#BaseException.__cause__" title="BaseException.__cause__"><code>__cause__</code></a>, <a class="reference internal" href="#BaseException.__context__" title="BaseException.__context__"><code>__context__</code></a> and <a class="reference internal" href="#BaseException.__notes__" title="BaseException.__notes__"><code>__notes__</code></a> fields. Empty nested groups are omitted from the result.</p> <p>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.</p> </dd>
+</dl> <dl class="py method"> <dt class="sig sig-object py" id="BaseExceptionGroup.split">
+<code>split(condition)</code> </dt> <dd>
+<p>Like <a class="reference internal" href="#BaseExceptionGroup.subgroup" title="BaseExceptionGroup.subgroup"><code>subgroup()</code></a>, but returns the pair <code>(match, rest)</code> where <code>match</code> is <code>subgroup(condition)</code> and <code>rest</code> is the remaining non-matching part.</p> </dd>
+</dl> <dl class="py method"> <dt class="sig sig-object py" id="BaseExceptionGroup.derive">
+<code>derive(excs)</code> </dt> <dd>
+<p>Returns an exception group with the same <a class="reference internal" href="#BaseExceptionGroup.message" title="BaseExceptionGroup.message"><code>message</code></a>, but which wraps the exceptions in <code>excs</code>.</p> <p>This method is used by <a class="reference internal" href="#BaseExceptionGroup.subgroup" title="BaseExceptionGroup.subgroup"><code>subgroup()</code></a> and <a class="reference internal" href="#BaseExceptionGroup.split" title="BaseExceptionGroup.split"><code>split()</code></a>. A subclass needs to override it in order to make <a class="reference internal" href="#BaseExceptionGroup.subgroup" title="BaseExceptionGroup.subgroup"><code>subgroup()</code></a> and <a class="reference internal" href="#BaseExceptionGroup.split" title="BaseExceptionGroup.split"><code>split()</code></a> return instances of the subclass rather than <a class="reference internal" href="#ExceptionGroup" title="ExceptionGroup"><code>ExceptionGroup</code></a>.</p> <p><a class="reference internal" href="#BaseExceptionGroup.subgroup" title="BaseExceptionGroup.subgroup"><code>subgroup()</code></a> and <a class="reference internal" href="#BaseExceptionGroup.split" title="BaseExceptionGroup.split"><code>split()</code></a> copy the <a class="reference internal" href="#BaseException.__traceback__" title="BaseException.__traceback__"><code>__traceback__</code></a>, <a class="reference internal" href="#BaseException.__cause__" title="BaseException.__cause__"><code>__cause__</code></a>, <a class="reference internal" href="#BaseException.__context__" title="BaseException.__context__"><code>__context__</code></a> and <a class="reference internal" href="#BaseException.__notes__" title="BaseException.__notes__"><code>__notes__</code></a> fields from the original exception group to the one returned by <a class="reference internal" href="#BaseExceptionGroup.derive" title="BaseExceptionGroup.derive"><code>derive()</code></a>, so these fields do not need to be updated by <a class="reference internal" href="#BaseExceptionGroup.derive" title="BaseExceptionGroup.derive"><code>derive()</code></a>.</p> <pre data-language="pycon3">&gt;&gt;&gt; class MyGroup(ExceptionGroup):
+... def derive(self, excs):
+... return MyGroup(self.message, excs)
+...
+&gt;&gt;&gt; e = MyGroup("eg", [ValueError(1), TypeError(2)])
+&gt;&gt;&gt; e.add_note("a note")
+&gt;&gt;&gt; e.__context__ = Exception("context")
+&gt;&gt;&gt; e.__cause__ = Exception("cause")
+&gt;&gt;&gt; try:
+... raise e
+... except Exception as e:
+... exc = e
+...
+&gt;&gt;&gt; match, rest = exc.split(ValueError)
+&gt;&gt;&gt; exc, exc.__context__, exc.__cause__, exc.__notes__
+(MyGroup('eg', [ValueError(1), TypeError(2)]), Exception('context'), Exception('cause'), ['a note'])
+&gt;&gt;&gt; match, match.__context__, match.__cause__, match.__notes__
+(MyGroup('eg', [ValueError(1)]), Exception('context'), Exception('cause'), ['a note'])
+&gt;&gt;&gt; rest, rest.__context__, rest.__cause__, rest.__notes__
+(MyGroup('eg', [TypeError(2)]), Exception('context'), Exception('cause'), ['a note'])
+&gt;&gt;&gt; exc.__traceback__ is match.__traceback__ is rest.__traceback__
+True
+</pre> </dd>
+</dl> <p>Note that <a class="reference internal" href="#BaseExceptionGroup" title="BaseExceptionGroup"><code>BaseExceptionGroup</code></a> defines <a class="reference internal" href="../reference/datamodel#object.__new__" title="object.__new__"><code>__new__()</code></a>, so subclasses that need a different constructor signature need to override that rather than <a class="reference internal" href="../reference/datamodel#object.__init__" title="object.__init__"><code>__init__()</code></a>. For example, the following defines an exception group subclass which accepts an exit_code and and constructs the group’s message from it.</p> <pre data-language="python">class Errors(ExceptionGroup):
+ def __new__(cls, errors, exit_code):
+ self = super().__new__(Errors, f"exit code: {exit_code}", errors)
+ self.exit_code = exit_code
+ return self
+
+ def derive(self, excs):
+ return Errors(excs, self.exit_code)
+</pre> <p>Like <a class="reference internal" href="#ExceptionGroup" title="ExceptionGroup"><code>ExceptionGroup</code></a>, any subclass of <a class="reference internal" href="#BaseExceptionGroup" title="BaseExceptionGroup"><code>BaseExceptionGroup</code></a> which is also a subclass of <a class="reference internal" href="#Exception" title="Exception"><code>Exception</code></a> can only wrap instances of <a class="reference internal" href="#Exception" title="Exception"><code>Exception</code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd>
+</dl> </section> <section id="exception-hierarchy"> <h2>Exception hierarchy</h2> <p>The class hierarchy for built-in exceptions is:</p> <pre data-language="text">BaseException
+ ├── BaseExceptionGroup
+ ├── GeneratorExit
+ ├── KeyboardInterrupt
+ ├── SystemExit
+ └── Exception
+ ├── ArithmeticError
+ │ ├── FloatingPointError
+ │ ├── OverflowError
+ │ └── ZeroDivisionError
+ ├── AssertionError
+ ├── AttributeError
+ ├── BufferError
+ ├── EOFError
+ ├── ExceptionGroup [BaseExceptionGroup]
+ ├── ImportError
+ │ └── ModuleNotFoundError
+ ├── LookupError
+ │ ├── IndexError
+ │ └── KeyError
+ ├── MemoryError
+ ├── NameError
+ │ └── UnboundLocalError
+ ├── OSError
+ │ ├── BlockingIOError
+ │ ├── ChildProcessError
+ │ ├── ConnectionError
+ │ │ ├── BrokenPipeError
+ │ │ ├── ConnectionAbortedError
+ │ │ ├── ConnectionRefusedError
+ │ │ └── ConnectionResetError
+ │ ├── FileExistsError
+ │ ├── FileNotFoundError
+ │ ├── InterruptedError
+ │ ├── IsADirectoryError
+ │ ├── NotADirectoryError
+ │ ├── PermissionError
+ │ ├── ProcessLookupError
+ │ └── TimeoutError
+ ├── ReferenceError
+ ├── RuntimeError
+ │ ├── NotImplementedError
+ │ └── RecursionError
+ ├── StopAsyncIteration
+ ├── StopIteration
+ ├── SyntaxError
+ │ └── IndentationError
+ │ └── TabError
+ ├── SystemError
+ ├── TypeError
+ ├── ValueError
+ │ └── UnicodeError
+ │ ├── UnicodeDecodeError
+ │ ├── UnicodeEncodeError
+ │ └── UnicodeTranslateError
+ └── Warning
+ ├── BytesWarning
+ ├── DeprecationWarning
+ ├── EncodingWarning
+ ├── FutureWarning
+ ├── ImportWarning
+ ├── PendingDeprecationWarning
+ ├── ResourceWarning
+ ├── RuntimeWarning
+ ├── SyntaxWarning
+ ├── UnicodeWarning
+ └── UserWarning
+</pre> </section> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
+ <a href="https://docs.python.org/3.12/library/exceptions.html" class="_attribution-link">https://docs.python.org/3.12/library/exceptions.html</a>
+ </p>
+</div>