parthtamu/rag-code-assistant
0
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4 <head>5 <meta charset="utf-8" />6 <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="Built-in Exceptions" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/exceptions.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="In Python, all exceptions must be instances of a class that derives from BaseException. In a try statement with an except clause that mentions a particular class, that clause also handles any excep..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_exceptions_cda5f1b3.png" />15<meta property="og:image:alt" content="In Python, all exceptions must be instances of a class that derives from BaseException. In a try statement with an except clause that mentions a particular class, that clause also handles any excep..." />16<meta name="description" content="In Python, all exceptions must be instances of a class that derives from BaseException. In a try statement with an except clause that mentions a particular class, that clause also handles any excep..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20 <title>Built-in Exceptions — Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21 22 <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23 <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24 <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25 <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26 <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27 28 <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29 <script src="../_static/doctools.js?v=9bcbadda"></script>30 <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31 <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32 33 <script src="../_static/sidebar.js"></script>34 35 <link rel="search" type="application/opensearchdescription+xml"36 title="Search within Python 3.15.0a6 documentation"37 href="../_static/opensearch.xml"/>38 <link rel="author" title="About these documents" href="../about.html" />39 <link rel="index" title="Index" href="../genindex.html" />40 <link rel="search" title="Search" href="../search.html" />41 <link rel="copyright" title="Copyright" href="../copyright.html" />42 <link rel="next" title="Thread Safety Guarantees" href="threadsafety.html" />43 <link rel="prev" title="Built-in Types" href="stdtypes.html" />44 45 46 <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47 48 <link rel="canonical" href="https://docs.python.org/3/library/exceptions.html">49 50 51 52 53 <style>54 @media only screen {55 table.full-width-table {56 width: 100%;57 }58 }59 </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61 <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62 <script type="text/javascript" src="../_static/copybutton.js"></script>63 <script type="text/javascript" src="../_static/menu.js"></script>64 <script type="text/javascript" src="../_static/search-focus.js"></script>65 <script type="text/javascript" src="../_static/themetoggle.js"></script> 66 <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67 <meta name="readthedocs-addons-api-version" content="1">68 69 </head>70<body>71<div class="mobile-nav">72 <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73 aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74 <nav class="nav-content" role="navigation">75 <label for="menuToggler" class="toggler__label">76 <span></span>77 </label>78 <span class="nav-items-wrapper">79 <a href="https://www.python.org/" class="nav-logo">80 <img src="../_static/py.svg" alt="Python logo">81 </a>82 <span class="version_switcher_placeholder"></span>83 <form role="search" class="search" action="../search.html" method="get">84 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85 <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>86 </svg>87 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88 <input type="submit" value="Go">89 </form>90 </span>91 </nav>92 <div class="menu-wrapper">93 <nav class="menu" role="navigation" aria-label="main navigation">94 <div class="language_switcher_placeholder"></div>95 96<label class="theme-selector-label">97 Theme98 <select class="theme-selector" oninput="activateTheme(this.value)">99 <option value="auto" selected>Auto</option>100 <option value="light">Light</option>101 <option value="dark">Dark</option>102 </select>103</label>104 <div>105 <h3><a href="../contents.html">Table of Contents</a></h3>106 <ul>107<li><a class="reference internal" href="#">Built-in Exceptions</a><ul>108<li><a class="reference internal" href="#exception-context">Exception context</a></li>109<li><a class="reference internal" href="#inheriting-from-built-in-exceptions">Inheriting from built-in exceptions</a></li>110<li><a class="reference internal" href="#base-classes">Base classes</a></li>111<li><a class="reference internal" href="#concrete-exceptions">Concrete exceptions</a><ul>112<li><a class="reference internal" href="#os-exceptions">OS exceptions</a></li>113</ul>114</li>115<li><a class="reference internal" href="#warnings">Warnings</a></li>116<li><a class="reference internal" href="#exception-groups">Exception groups</a></li>117<li><a class="reference internal" href="#exception-hierarchy">Exception hierarchy</a></li>118</ul>119</li>120</ul>121 122 </div>123 <div>124 <h4>Previous topic</h4>125 <p class="topless"><a href="stdtypes.html"126 title="previous chapter">Built-in Types</a></p>127 </div>128 <div>129 <h4>Next topic</h4>130 <p class="topless"><a href="threadsafety.html"131 title="next chapter">Thread Safety Guarantees</a></p>132 </div>133 <script>134 document.addEventListener('DOMContentLoaded', () => {135 const title = document.querySelector('meta[property="og:title"]').content;136 const elements = document.querySelectorAll('.improvepage');137 const pageurl = window.location.href.split('?')[0];138 elements.forEach(element => {139 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));140 url.searchParams.set('pagetitle', title);141 url.searchParams.set('pageurl', pageurl);142 url.searchParams.set('pagesource', "library/exceptions.rst");143 element.href = url.toString();144 });145 });146 </script>147 <div role="note" aria-label="source link">148 <h3>This page</h3>149 <ul class="this-page-menu">150 <li><a href="../bugs.html">Report a bug</a></li>151 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>152 <li>153 <a href="https://github.com/python/cpython/blob/main/Doc/library/exceptions.rst?plain=1"154 rel="nofollow">Show source155 </a>156 </li>157 158 </ul>159 </div>160 </nav>161 </div>162</div>163 164 165 <div class="related" role="navigation" aria-label="Related">166 <h3>Navigation</h3>167 <ul>168 <li class="right" style="margin-right: 10px">169 <a href="../genindex.html" title="General Index"170 accesskey="I">index</a></li>171 <li class="right" >172 <a href="../py-modindex.html" title="Python Module Index"173 >modules</a> |</li>174 <li class="right" >175 <a href="threadsafety.html" title="Thread Safety Guarantees"176 accesskey="N">next</a> |</li>177 <li class="right" >178 <a href="stdtypes.html" title="Built-in Types"179 accesskey="P">previous</a> |</li>180 181 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>182 <li><a href="https://www.python.org/">Python</a> »</li>183 <li class="switchers">184 <div class="language_switcher_placeholder"></div>185 <div class="version_switcher_placeholder"></div>186 </li>187 <li>188 189 </li>190 <li id="cpython-language-and-version">191 <a href="../index.html">3.15.0a6 Documentation</a> »192 </li>193 194 <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">The Python Standard Library</a> »</li>195 <li class="nav-item nav-item-this"><a href="">Built-in Exceptions</a></li>196 <li class="right">197 198 199 <div class="inline-search" role="search">200 <form class="inline-search" action="../search.html" method="get">201 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">202 <input type="submit" value="Go">203 </form>204 </div>205 |206 </li>207 <li class="right">208<label class="theme-selector-label">209 Theme210 <select class="theme-selector" oninput="activateTheme(this.value)">211 <option value="auto" selected>Auto</option>212 <option value="light">Light</option>213 <option value="dark">Dark</option>214 </select>215</label> |</li>216 217 </ul>218 </div> 219 220 <div class="document">221 <div class="documentwrapper">222 <div class="bodywrapper">223 <div class="body" role="main">224 225 <section id="built-in-exceptions">226<span id="bltin-exceptions"></span><h1>Built-in Exceptions<a class="headerlink" href="#built-in-exceptions" title="Link to this heading">¶</a></h1>227<p id="index-0">In Python, all exceptions must be instances of a class that derives from228<a class="reference internal" href="#BaseException" title="BaseException"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseException</span></code></a>. In a <a class="reference internal" href="../reference/compound_stmts.html#try"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">try</span></code></a> statement with an <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a>229clause that mentions a particular class, that clause also handles any exception230classes derived from that class (but not exception classes from which <em>it</em> is231derived). Two exception classes that are not related via subclassing are never232equivalent, even if they have the same name.</p>233<p id="index-1">The built-in exceptions listed in this chapter can be generated by the interpreter or234built-in functions. Except where mentioned, they have an “associated value”235indicating the detailed cause of the error. This may be a string or a tuple of236several items of information (e.g., an error code and a string explaining the237code). The associated value is usually passed as arguments to the exception238class’s constructor.</p>239<p>User code can raise built-in exceptions. This can be used to test an exception240handler or to report an error condition “just like” the situation in which the241interpreter raises the same exception; but beware that there is nothing to242prevent user code from raising an inappropriate error.</p>243<p>The built-in exception classes can be subclassed to define new exceptions;244programmers are encouraged to derive new exceptions from the <a class="reference internal" href="#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a>245class or one of its subclasses, and not from <a class="reference internal" href="#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a>. More246information on defining exceptions is available in the Python Tutorial under247<a class="reference internal" href="../tutorial/errors.html#tut-userexceptions"><span class="std std-ref">User-defined Exceptions</span></a>.</p>248<section id="exception-context">249<h2>Exception context<a class="headerlink" href="#exception-context" title="Link to this heading">¶</a></h2>250<p id="index-2">Three attributes on exception objects provide information about the context in251which the exception was raised:</p>252<dl class="py attribute">253<dt class="sig sig-object py" id="BaseException.__context__">254<span class="sig-prename descclassname"><span class="pre">BaseException.</span></span><span class="sig-name descname"><span class="pre">__context__</span></span><a class="headerlink" href="#BaseException.__context__" title="Link to this definition">¶</a></dt>255<dt class="sig sig-object py" id="BaseException.__cause__">256<span class="sig-prename descclassname"><span class="pre">BaseException.</span></span><span class="sig-name descname"><span class="pre">__cause__</span></span><a class="headerlink" href="#BaseException.__cause__" title="Link to this definition">¶</a></dt>257<dt class="sig sig-object py" id="BaseException.__suppress_context__">258<span class="sig-prename descclassname"><span class="pre">BaseException.</span></span><span class="sig-name descname"><span class="pre">__suppress_context__</span></span><a class="headerlink" href="#BaseException.__suppress_context__" title="Link to this definition">¶</a></dt>259<dd><p>When raising a new exception while another exception260is already being handled, the new exception’s261<code class="xref py py-attr docutils literal notranslate"><span class="pre">__context__</span></code> attribute is automatically set to the handled262exception. An exception may be handled when an <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> or263<a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">finally</span></code></a> clause, or a <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement, is used.</p>264<p>This implicit exception context can be265supplemented with an explicit cause by using <code class="xref std std-keyword docutils literal notranslate"><span class="pre">from</span></code> with266<a class="reference internal" href="../reference/simple_stmts.html#raise"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">raise</span></code></a>:</p>267<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">raise</span> <span class="n">new_exc</span> <span class="kn">from</span><span class="w"> </span><span class="nn">original_exc</span>268</pre></div>269</div>270<p>The expression following <a class="reference internal" href="../reference/simple_stmts.html#raise"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">from</span></code></a> must be an exception or <code class="docutils literal notranslate"><span class="pre">None</span></code>. It271will be set as <code class="xref py py-attr docutils literal notranslate"><span class="pre">__cause__</span></code> on the raised exception. Setting272<code class="xref py py-attr docutils literal notranslate"><span class="pre">__cause__</span></code> also implicitly sets the <code class="xref py py-attr docutils literal notranslate"><span class="pre">__suppress_context__</span></code>273attribute to <code class="docutils literal notranslate"><span class="pre">True</span></code>, so that using <code class="docutils literal notranslate"><span class="pre">raise</span> <span class="pre">new_exc</span> <span class="pre">from</span> <span class="pre">None</span></code>274effectively replaces the old exception with the new one for display275purposes (e.g. converting <a class="reference internal" href="#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> to <a class="reference internal" href="#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a>), while276leaving the old exception available in <code class="xref py py-attr docutils literal notranslate"><span class="pre">__context__</span></code> for introspection277when debugging.</p>278<p>The default traceback display code shows these chained exceptions in279addition to the traceback for the exception itself. An explicitly chained280exception in <code class="xref py py-attr docutils literal notranslate"><span class="pre">__cause__</span></code> is always shown when present. An implicitly281chained exception in <code class="xref py py-attr docutils literal notranslate"><span class="pre">__context__</span></code> is shown only if <code class="xref py py-attr docutils literal notranslate"><span class="pre">__cause__</span></code>282is <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">__suppress_context__</span></code> is false.</p>283<p>In either case, the exception itself is always shown after any chained284exceptions so that the final line of the traceback always shows the last285exception that was raised.</p>286</dd></dl>287 288</section>289<section id="inheriting-from-built-in-exceptions">290<h2>Inheriting from built-in exceptions<a class="headerlink" href="#inheriting-from-built-in-exceptions" title="Link to this heading">¶</a></h2>291<p>User code can create subclasses that inherit from an exception type.292It’s recommended to only subclass one exception type at a time to avoid293any possible conflicts between how the bases handle the <code class="docutils literal notranslate"><span class="pre">args</span></code>294attribute, as well as due to possible memory layout incompatibilities.</p>295<div class="impl-detail compound">296<p><strong>CPython implementation detail:</strong> Most built-in exceptions are implemented in C for efficiency, see:297<a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Objects/exceptions.c">Objects/exceptions.c</a>. Some have custom memory layouts298which makes it impossible to create a subclass that inherits from299multiple exception types. The memory layout of a type is an implementation300detail and might change between Python versions, leading to new301conflicts in the future. Therefore, it’s recommended to avoid302subclassing multiple exception types altogether.</p>303</div>304</section>305<section id="base-classes">306<h2>Base classes<a class="headerlink" href="#base-classes" title="Link to this heading">¶</a></h2>307<p>The following exceptions are used mostly as base classes for other exceptions.</p>308<dl class="py exception">309<dt class="sig sig-object py" id="BaseException">310<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">BaseException</span></span><a class="headerlink" href="#BaseException" title="Link to this definition">¶</a></dt>311<dd><p>The base class for all built-in exceptions. It is not meant to be directly312inherited by user-defined classes (for that, use <a class="reference internal" href="#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a>). If313<a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a> is called on an instance of this class, the representation of314the argument(s) to the instance are returned, or the empty string when315there were no arguments.</p>316<dl class="py attribute">317<dt class="sig sig-object py" id="BaseException.args">318<span class="sig-name descname"><span class="pre">args</span></span><a class="headerlink" href="#BaseException.args" title="Link to this definition">¶</a></dt>319<dd><p>The tuple of arguments given to the exception constructor. Some built-in320exceptions (like <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>) expect a certain number of arguments and321assign a special meaning to the elements of this tuple, while others are322usually called only with a single string giving an error message.</p>323</dd></dl>324 325<dl class="py method">326<dt class="sig sig-object py" id="BaseException.with_traceback">327<span class="sig-name descname"><span class="pre">with_traceback</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tb</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#BaseException.with_traceback" title="Link to this definition">¶</a></dt>328<dd><p>This method sets <em>tb</em> as the new traceback for the exception and returns329the exception object. It was more commonly used before the exception330chaining 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 example331shows how we can convert an instance of <code class="docutils literal notranslate"><span class="pre">SomeException</span></code> into an332instance of <code class="docutils literal notranslate"><span class="pre">OtherException</span></code> while preserving the traceback. Once333raised, the current frame is pushed onto the traceback of the334<code class="docutils literal notranslate"><span class="pre">OtherException</span></code>, as would have happened to the traceback of the335original <code class="docutils literal notranslate"><span class="pre">SomeException</span></code> had we allowed it to propagate to the caller.</p>336<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span>337 <span class="o">...</span>338<span class="k">except</span> <span class="n">SomeException</span><span class="p">:</span>339 <span class="n">tb</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">exception</span><span class="p">()</span><span class="o">.</span><span class="n">__traceback__</span>340 <span class="k">raise</span> <span class="n">OtherException</span><span class="p">(</span><span class="o">...</span><span class="p">)</span><span class="o">.</span><span class="n">with_traceback</span><span class="p">(</span><span class="n">tb</span><span class="p">)</span>341</pre></div>342</div>343</dd></dl>344 345<dl class="py attribute">346<dt class="sig sig-object py" id="BaseException.__traceback__">347<span class="sig-name descname"><span class="pre">__traceback__</span></span><a class="headerlink" href="#BaseException.__traceback__" title="Link to this definition">¶</a></dt>348<dd><p>A writable field that holds the349<a class="reference internal" href="../reference/datamodel.html#traceback-objects"><span class="std std-ref">traceback object</span></a> associated with this350exception. See also: <a class="reference internal" href="../reference/simple_stmts.html#raise"><span class="std std-ref">The raise statement</span></a>.</p>351</dd></dl>352 353<dl class="py method">354<dt class="sig sig-object py" id="BaseException.add_note">355<span class="sig-name descname"><span class="pre">add_note</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">note</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#BaseException.add_note" title="Link to this definition">¶</a></dt>356<dd><p>Add the string <code class="docutils literal notranslate"><span class="pre">note</span></code> to the exception’s notes which appear in the standard357traceback after the exception string. A <a class="reference internal" href="#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> is raised if <code class="docutils literal notranslate"><span class="pre">note</span></code>358is not a string.</p>359<div class="versionadded">360<p><span class="versionmodified added">Added in version 3.11.</span></p>361</div>362</dd></dl>363 364<dl class="py attribute">365<dt class="sig sig-object py" id="BaseException.__notes__">366<span class="sig-name descname"><span class="pre">__notes__</span></span><a class="headerlink" href="#BaseException.__notes__" title="Link to this definition">¶</a></dt>367<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 class="xref py py-meth docutils literal notranslate"><span class="pre">add_note()</span></code></a>.368This attribute is created when <code class="xref py py-meth docutils literal notranslate"><span class="pre">add_note()</span></code> is called.</p>369<div class="versionadded">370<p><span class="versionmodified added">Added in version 3.11.</span></p>371</div>372</dd></dl>373 374</dd></dl>375 376<dl class="py exception">377<dt class="sig sig-object py" id="Exception">378<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">Exception</span></span><a class="headerlink" href="#Exception" title="Link to this definition">¶</a></dt>379<dd><p>All built-in, non-system-exiting exceptions are derived from this class. All380user-defined exceptions should also be derived from this class.</p>381</dd></dl>382 383<dl class="py exception">384<dt class="sig sig-object py" id="ArithmeticError">385<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ArithmeticError</span></span><a class="headerlink" href="#ArithmeticError" title="Link to this definition">¶</a></dt>386<dd><p>The base class for those built-in exceptions that are raised for various387arithmetic errors: <a class="reference internal" href="#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a>, <a class="reference internal" href="#ZeroDivisionError" title="ZeroDivisionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ZeroDivisionError</span></code></a>,388<a class="reference internal" href="#FloatingPointError" title="FloatingPointError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FloatingPointError</span></code></a>.</p>389</dd></dl>390 391<dl class="py exception">392<dt class="sig sig-object py" id="BufferError">393<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">BufferError</span></span><a class="headerlink" href="#BufferError" title="Link to this definition">¶</a></dt>394<dd><p>Raised when a <a class="reference internal" href="../c-api/buffer.html#bufferobjects"><span class="std std-ref">buffer</span></a> related operation cannot be395performed.</p>396</dd></dl>397 398<dl class="py exception">399<dt class="sig sig-object py" id="LookupError">400<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">LookupError</span></span><a class="headerlink" href="#LookupError" title="Link to this definition">¶</a></dt>401<dd><p>The base class for the exceptions that are raised when a key or index used on402a mapping or sequence is invalid: <a class="reference internal" href="#IndexError" title="IndexError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndexError</span></code></a>, <a class="reference internal" href="#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a>. This403can be raised directly by <a class="reference internal" href="codecs.html#codecs.lookup" title="codecs.lookup"><code class="xref py py-func docutils literal notranslate"><span class="pre">codecs.lookup()</span></code></a>.</p>404</dd></dl>405 406</section>407<section id="concrete-exceptions">408<h2>Concrete exceptions<a class="headerlink" href="#concrete-exceptions" title="Link to this heading">¶</a></h2>409<p>The following exceptions are the exceptions that are usually raised.</p>410<dl class="py exception">411<dt class="sig sig-object py" id="AssertionError">412<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">AssertionError</span></span><a class="headerlink" href="#AssertionError" title="Link to this definition">¶</a></dt>413<dd><p id="index-4">Raised when an <a class="reference internal" href="../reference/simple_stmts.html#assert"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">assert</span></code></a> statement fails.</p>414</dd></dl>415 416<dl class="py exception">417<dt class="sig sig-object py" id="AttributeError">418<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">AttributeError</span></span><a class="headerlink" href="#AttributeError" title="Link to this definition">¶</a></dt>419<dd><p>Raised when an attribute reference (see <a class="reference internal" href="../reference/expressions.html#attribute-references"><span class="std std-ref">Attribute references</span></a>) or420assignment fails. (When an object does not support attribute references or421attribute assignments at all, <a class="reference internal" href="#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> is raised.)</p>422<p>The optional <em>name</em> and <em>obj</em> keyword-only arguments423set the corresponding attributes:</p>424<dl class="py attribute">425<dt class="sig sig-object py" id="AttributeError.name">426<span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#AttributeError.name" title="Link to this definition">¶</a></dt>427<dd><p>The name of the attribute that was attempted to be accessed.</p>428</dd></dl>429 430<dl class="py attribute">431<dt class="sig sig-object py" id="AttributeError.obj">432<span class="sig-name descname"><span class="pre">obj</span></span><a class="headerlink" href="#AttributeError.obj" title="Link to this definition">¶</a></dt>433<dd><p>The object that was accessed for the named attribute.</p>434</dd></dl>435 436<div class="versionchanged">437<p><span class="versionmodified changed">Changed in version 3.10: </span>Added the <a class="reference internal" href="#AttributeError.name" title="AttributeError.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> and <a class="reference internal" href="#AttributeError.obj" title="AttributeError.obj"><code class="xref py py-attr docutils literal notranslate"><span class="pre">obj</span></code></a> attributes.</p>438</div>439</dd></dl>440 441<dl class="py exception">442<dt class="sig sig-object py" id="EOFError">443<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">EOFError</span></span><a class="headerlink" href="#EOFError" title="Link to this definition">¶</a></dt>444<dd><p>Raised when the <a class="reference internal" href="functions.html#input" title="input"><code class="xref py py-func docutils literal notranslate"><span class="pre">input()</span></code></a> function hits an end-of-file condition (EOF)445without reading any data. (Note: the <code class="xref py py-meth docutils literal notranslate"><span class="pre">io.IOBase.read()</span></code> and446<a class="reference internal" href="io.html#io.IOBase.readline" title="io.IOBase.readline"><code class="xref py py-meth docutils literal notranslate"><span class="pre">io.IOBase.readline()</span></code></a> methods return an empty string when they hit EOF.)</p>447</dd></dl>448 449<dl class="py exception">450<dt class="sig sig-object py" id="FloatingPointError">451<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">FloatingPointError</span></span><a class="headerlink" href="#FloatingPointError" title="Link to this definition">¶</a></dt>452<dd><p>Not currently used.</p>453</dd></dl>454 455<dl class="py exception">456<dt class="sig sig-object py" id="GeneratorExit">457<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">GeneratorExit</span></span><a class="headerlink" href="#GeneratorExit" title="Link to this definition">¶</a></dt>458<dd><p>Raised when a <a class="reference internal" href="../glossary.html#term-generator"><span class="xref std std-term">generator</span></a> or <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> is closed;459see <a class="reference internal" href="../reference/expressions.html#generator.close" title="generator.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">generator.close()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#coroutine.close" title="coroutine.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">coroutine.close()</span></code></a>. It460directly inherits from <a class="reference internal" href="#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a> instead of <a class="reference internal" href="#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a> since461it is technically not an error.</p>462</dd></dl>463 464<dl class="py exception">465<dt class="sig sig-object py" id="ImportError">466<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ImportError</span></span><a class="headerlink" href="#ImportError" title="Link to this definition">¶</a></dt>467<dd><p>Raised when the <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> statement has troubles trying to468load a module. Also raised when the “from list” in <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">...</span> <span class="pre">import</span></code>469has a name that cannot be found.</p>470<p>The optional <em>name</em> and <em>path</em> keyword-only arguments471set the corresponding attributes:</p>472<dl class="py attribute">473<dt class="sig sig-object py" id="ImportError.name">474<span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#ImportError.name" title="Link to this definition">¶</a></dt>475<dd><p>The name of the module that was attempted to be imported.</p>476</dd></dl>477 478<dl class="py attribute">479<dt class="sig sig-object py" id="ImportError.path">480<span class="sig-name descname"><span class="pre">path</span></span><a class="headerlink" href="#ImportError.path" title="Link to this definition">¶</a></dt>481<dd><p>The path to any file which triggered the exception.</p>482</dd></dl>483 484<div class="versionchanged">485<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <a class="reference internal" href="#ImportError.name" title="ImportError.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> and <a class="reference internal" href="#ImportError.path" title="ImportError.path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">path</span></code></a> attributes.</p>486</div>487</dd></dl>488 489<dl class="py exception">490<dt class="sig sig-object py" id="ModuleNotFoundError">491<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ModuleNotFoundError</span></span><a class="headerlink" href="#ModuleNotFoundError" title="Link to this definition">¶</a></dt>492<dd><p>A subclass of <a class="reference internal" href="#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> which is raised by <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a>493when a module could not be located. It is also raised when <code class="docutils literal notranslate"><span class="pre">None</span></code>494is found in <a class="reference internal" href="sys.html#sys.modules" title="sys.modules"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.modules</span></code></a>.</p>495<div class="versionadded">496<p><span class="versionmodified added">Added in version 3.6.</span></p>497</div>498</dd></dl>499 500<dl class="py exception">501<dt class="sig sig-object py" id="ImportCycleError">502<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ImportCycleError</span></span><a class="headerlink" href="#ImportCycleError" title="Link to this definition">¶</a></dt>503<dd><p>A subclass of <a class="reference internal" href="#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> which is raised when a lazy import fails504because it (directly or indirectly) tries to import itself.</p>505<div class="versionadded">506<p><span class="versionmodified added">Added in version 3.15.0a6 (unreleased).</span></p>507</div>508</dd></dl>509 510<dl class="py exception">511<dt class="sig sig-object py" id="IndexError">512<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">IndexError</span></span><a class="headerlink" href="#IndexError" title="Link to this definition">¶</a></dt>513<dd><p>Raised when a sequence subscript is out of range. (Slice indices are514silently truncated to fall in the allowed range; if an index is not an515integer, <a class="reference internal" href="#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> is raised.)</p>516</dd></dl>517 518<dl class="py exception">519<dt class="sig sig-object py" id="KeyError">520<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">KeyError</span></span><a class="headerlink" href="#KeyError" title="Link to this definition">¶</a></dt>521<dd><p>Raised when a mapping (dictionary) key is not found in the set of existing keys.</p>522</dd></dl>523 524<dl class="py exception">525<dt class="sig sig-object py" id="KeyboardInterrupt">526<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">KeyboardInterrupt</span></span><a class="headerlink" href="#KeyboardInterrupt" title="Link to this definition">¶</a></dt>527<dd><p>Raised when the user hits the interrupt key (normally <kbd class="kbd docutils literal notranslate">Control</kbd>-<kbd class="kbd docutils literal notranslate">C</kbd> or528<kbd class="kbd docutils literal notranslate">Delete</kbd>). During execution, a check for interrupts is made529regularly. The exception inherits from <a class="reference internal" href="#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a> so as to not be530accidentally caught by code that catches <a class="reference internal" href="#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a> and thus prevent531the interpreter from exiting.</p>532<div class="admonition note">533<p class="admonition-title">Note</p>534<p>Catching a <code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyboardInterrupt</span></code> requires special consideration.535Because it can be raised at unpredictable points, it may, in some536circumstances, leave the running program in an inconsistent state. It is537generally best to allow <code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyboardInterrupt</span></code> to end the program as538quickly as possible or avoid raising it entirely. (See539<a class="reference internal" href="signal.html#handlers-and-exceptions"><span class="std std-ref">Note on Signal Handlers and Exceptions</span></a>.)</p>540</div>541</dd></dl>542 543<dl class="py exception">544<dt class="sig sig-object py" id="MemoryError">545<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">MemoryError</span></span><a class="headerlink" href="#MemoryError" title="Link to this definition">¶</a></dt>546<dd><p>Raised when an operation runs out of memory but the situation may still be547rescued (by deleting some objects). The associated value is a string indicating548what kind of (internal) operation ran out of memory. Note that because of the549underlying memory management architecture (C’s <code class="xref c c-func docutils literal notranslate"><span class="pre">malloc()</span></code> function), the550interpreter may not always be able to completely recover from this situation; it551nevertheless raises an exception so that a stack traceback can be printed, in552case a run-away program was the cause.</p>553</dd></dl>554 555<dl class="py exception">556<dt class="sig sig-object py" id="NameError">557<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">NameError</span></span><a class="headerlink" href="#NameError" title="Link to this definition">¶</a></dt>558<dd><p>Raised when a local or global name is not found. This applies only to559unqualified names. The associated value is an error message that includes the560name that could not be found.</p>561<p>The optional <em>name</em> keyword-only argument sets the attribute:</p>562<dl class="py attribute">563<dt class="sig sig-object py" id="NameError.name">564<span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#NameError.name" title="Link to this definition">¶</a></dt>565<dd><p>The name of the variable that was attempted to be accessed.</p>566</dd></dl>567 568<div class="versionchanged">569<p><span class="versionmodified changed">Changed in version 3.10: </span>Added the <a class="reference internal" href="#NameError.name" title="NameError.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> attribute.</p>570</div>571</dd></dl>572 573<dl class="py exception">574<dt class="sig sig-object py" id="NotImplementedError">575<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">NotImplementedError</span></span><a class="headerlink" href="#NotImplementedError" title="Link to this definition">¶</a></dt>576<dd><p>This exception is derived from <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>. In user defined base577classes, abstract methods should raise this exception when they require578derived classes to override the method, or while the class is being579developed to indicate that the real implementation still needs to be added.</p>580<div class="admonition note">581<p class="admonition-title">Note</p>582<p>It should not be used to indicate that an operator or method is not583meant to be supported at all – in that case either leave the operator /584method undefined or, if a subclass, set it to <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-data docutils literal notranslate"><span class="pre">None</span></code></a>.</p>585</div>586<div class="admonition caution">587<p class="admonition-title">Caution</p>588<p><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code> and <code class="xref py py-data docutils literal notranslate"><span class="pre">NotImplemented</span></code> are not589interchangeable. This exception should only be used as described590above; see <a class="reference internal" href="constants.html#NotImplemented" title="NotImplemented"><code class="xref py py-data docutils literal notranslate"><span class="pre">NotImplemented</span></code></a> for details on correct usage of591the built-in constant.</p>592</div>593</dd></dl>594 595<dl class="py exception">596<dt class="sig sig-object py" id="OSError">597<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">OSError</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">arg</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#OSError" title="Link to this definition">¶</a></dt>598<dt class="sig sig-object py">599<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">OSError</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">errno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">strerror</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">winerror</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">filename2</span></span></em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span></dt>600<dd><p id="index-5">This exception is raised when a system function returns a system-related601error, including I/O failures such as “file not found” or “disk full”602(not for illegal argument types or other incidental errors).</p>603<p>The second form of the constructor sets the corresponding attributes,604described below. The attributes default to <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> if not605specified. For backwards compatibility, if three arguments are passed,606the <a class="reference internal" href="#BaseException.args" title="BaseException.args"><code class="xref py py-attr docutils literal notranslate"><span class="pre">args</span></code></a> attribute contains only a 2-tuple607of the first two constructor arguments.</p>608<p>The constructor often actually returns a subclass of <code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code>, as609described in <a class="reference internal" href="#os-exceptions">OS exceptions</a> below. The particular subclass depends on610the final <a class="reference internal" href="#OSError.errno" title="OSError.errno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">errno</span></code></a> value. This behaviour only occurs when611constructing <code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code> directly or via an alias, and is not612inherited when subclassing.</p>613<dl class="py attribute">614<dt class="sig sig-object py" id="OSError.errno">615<span class="sig-name descname"><span class="pre">errno</span></span><a class="headerlink" href="#OSError.errno" title="Link to this definition">¶</a></dt>616<dd><p>A numeric error code from the C variable <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code>.</p>617</dd></dl>618 619<dl class="py attribute">620<dt class="sig sig-object py" id="OSError.winerror">621<span class="sig-name descname"><span class="pre">winerror</span></span><a class="headerlink" href="#OSError.winerror" title="Link to this definition">¶</a></dt>622<dd><p>Under Windows, this gives you the native623Windows error code. The <a class="reference internal" href="#OSError.errno" title="OSError.errno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">errno</span></code></a> attribute is then an approximate624translation, in POSIX terms, of that native error code.</p>625<p>Under Windows, if the <em>winerror</em> constructor argument is an integer,626the <a class="reference internal" href="#OSError.errno" title="OSError.errno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">errno</span></code></a> attribute is determined from the Windows error code,627and the <em>errno</em> argument is ignored. On other platforms, the628<em>winerror</em> argument is ignored, and the <a class="reference internal" href="#OSError.winerror" title="OSError.winerror"><code class="xref py py-attr docutils literal notranslate"><span class="pre">winerror</span></code></a> attribute629does not exist.</p>630</dd></dl>631 632<dl class="py attribute">633<dt class="sig sig-object py" id="OSError.strerror">634<span class="sig-name descname"><span class="pre">strerror</span></span><a class="headerlink" href="#OSError.strerror" title="Link to this definition">¶</a></dt>635<dd><p>The corresponding error message, as provided by636the operating system. It is formatted by the C637functions <code class="xref c c-func docutils literal notranslate"><span class="pre">perror()</span></code> under POSIX, and <code class="xref c c-func docutils literal notranslate"><span class="pre">FormatMessage()</span></code>638under Windows.</p>639</dd></dl>640 641<dl class="py attribute">642<dt class="sig sig-object py" id="OSError.filename">643<span class="sig-name descname"><span class="pre">filename</span></span><a class="headerlink" href="#OSError.filename" title="Link to this definition">¶</a></dt>644<dt class="sig sig-object py" id="OSError.filename2">645<span class="sig-name descname"><span class="pre">filename2</span></span><a class="headerlink" href="#OSError.filename2" title="Link to this definition">¶</a></dt>646<dd><p>For exceptions that involve a file system path (such as <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> or647<a class="reference internal" href="os.html#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.unlink()</span></code></a>), <a class="reference internal" href="#OSError.filename" title="OSError.filename"><code class="xref py py-attr docutils literal notranslate"><span class="pre">filename</span></code></a> is the file name passed to the function.648For functions that involve two file system paths (such as649<a class="reference internal" href="os.html#os.rename" title="os.rename"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.rename()</span></code></a>), <a class="reference internal" href="#OSError.filename2" title="OSError.filename2"><code class="xref py py-attr docutils literal notranslate"><span class="pre">filename2</span></code></a> corresponds to the second650file name passed to the function.</p>651</dd></dl>652 653<div class="versionchanged">654<p><span class="versionmodified changed">Changed in version 3.3: </span><a class="reference internal" href="#EnvironmentError" title="EnvironmentError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">EnvironmentError</span></code></a>, <a class="reference internal" href="#IOError" title="IOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IOError</span></code></a>, <a class="reference internal" href="#WindowsError" title="WindowsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">WindowsError</span></code></a>,655<a class="reference internal" href="socket.html#socket.error" title="socket.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">socket.error</span></code></a>, <a class="reference internal" href="select.html#select.error" title="select.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">select.error</span></code></a> and656<code class="xref py py-exc docutils literal notranslate"><span class="pre">mmap.error</span></code> have been merged into <code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code>, and the657constructor may return a subclass.</p>658</div>659<div class="versionchanged">660<p><span class="versionmodified changed">Changed in version 3.4: </span>The <a class="reference internal" href="#OSError.filename" title="OSError.filename"><code class="xref py py-attr docutils literal notranslate"><span class="pre">filename</span></code></a> attribute is now the original file name passed to661the function, instead of the name encoded to or decoded from the662<a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>. Also, the <em>filename2</em>663constructor argument and attribute was added.</p>664</div>665</dd></dl>666 667<dl class="py exception">668<dt class="sig sig-object py" id="OverflowError">669<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">OverflowError</span></span><a class="headerlink" href="#OverflowError" title="Link to this definition">¶</a></dt>670<dd><p>Raised when the result of an arithmetic operation is too large to be671represented. This cannot occur for integers (which would rather raise672<a class="reference internal" href="#MemoryError" title="MemoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">MemoryError</span></code></a> than give up). However, for historical reasons,673OverflowError is sometimes raised for integers that are outside a required674range. Because of the lack of standardization of floating-point exception675handling in C, most floating-point operations are not checked.</p>676</dd></dl>677 678<dl class="py exception">679<dt class="sig sig-object py" id="PythonFinalizationError">680<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">PythonFinalizationError</span></span><a class="headerlink" href="#PythonFinalizationError" title="Link to this definition">¶</a></dt>681<dd><p>This exception is derived from <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>. It is raised when682an operation is blocked during interpreter shutdown also known as683<a class="reference internal" href="../glossary.html#term-interpreter-shutdown"><span class="xref std std-term">Python finalization</span></a>.</p>684<p>Examples of operations which can be blocked with a685<code class="xref py py-exc docutils literal notranslate"><span class="pre">PythonFinalizationError</span></code> during the Python finalization:</p>686<ul class="simple">687<li><p>Creating a new Python thread.</p></li>688<li><p><a class="reference internal" href="threading.html#threading.Thread.join" title="threading.Thread.join"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Joining</span></code></a> a running daemon thread.</p></li>689<li><p><a class="reference internal" href="os.html#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fork()</span></code></a>,</p></li>690<li><p>acquiring a lock such as <a class="reference internal" href="threading.html#threading.Lock" title="threading.Lock"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Lock</span></code></a>, when it is known that691the operation would otherwise deadlock.</p></li>692</ul>693<p>See also the <a class="reference internal" href="sys.html#sys.is_finalizing" title="sys.is_finalizing"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.is_finalizing()</span></code></a> function.</p>694<div class="versionadded">695<p><span class="versionmodified added">Added in version 3.13: </span>Previously, a plain <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> was raised.</p>696</div>697<div class="versionchanged">698<p><span class="versionmodified changed">Changed in version 3.14: </span><a class="reference internal" href="threading.html#threading.Thread.join" title="threading.Thread.join"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Thread.join()</span></code></a> can now raise this exception.</p>699</div>700<div class="versionchanged">701<p><span class="versionmodified changed">Changed in version 3.15: </span>This exception may be raised when acquiring <a class="reference internal" href="threading.html#threading.Lock" title="threading.Lock"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Lock()</span></code></a>702or <a class="reference internal" href="threading.html#threading.RLock" title="threading.RLock"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.RLock()</span></code></a>.</p>703</div>704</dd></dl>705 706<dl class="py exception">707<dt class="sig sig-object py" id="RecursionError">708<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">RecursionError</span></span><a class="headerlink" href="#RecursionError" title="Link to this definition">¶</a></dt>709<dd><p>This exception is derived from <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>. It is raised when the710interpreter detects that the maximum recursion depth (see711<a class="reference internal" href="sys.html#sys.getrecursionlimit" title="sys.getrecursionlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getrecursionlimit()</span></code></a>) is exceeded.</p>712<div class="versionadded">713<p><span class="versionmodified added">Added in version 3.5: </span>Previously, a plain <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> was raised.</p>714</div>715</dd></dl>716 717<dl class="py exception">718<dt class="sig sig-object py" id="ReferenceError">719<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ReferenceError</span></span><a class="headerlink" href="#ReferenceError" title="Link to this definition">¶</a></dt>720<dd><p>This exception is raised when a weak reference proxy, created by the721<a class="reference internal" href="weakref.html#weakref.proxy" title="weakref.proxy"><code class="xref py py-func docutils literal notranslate"><span class="pre">weakref.proxy()</span></code></a> function, is used to access an attribute of the referent722after it has been garbage collected. For more information on weak references,723see the <a class="reference internal" href="weakref.html#module-weakref" title="weakref: Support for weak references and weak dictionaries."><code class="xref py py-mod docutils literal notranslate"><span class="pre">weakref</span></code></a> module.</p>724</dd></dl>725 726<dl class="py exception">727<dt class="sig sig-object py" id="RuntimeError">728<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">RuntimeError</span></span><a class="headerlink" href="#RuntimeError" title="Link to this definition">¶</a></dt>729<dd><p>Raised when an error is detected that doesn’t fall in any of the other730categories. The associated value is a string indicating what precisely went731wrong.</p>732</dd></dl>733 734<dl class="py exception">735<dt class="sig sig-object py" id="StopIteration">736<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">StopIteration</span></span><a class="headerlink" href="#StopIteration" title="Link to this definition">¶</a></dt>737<dd><p>Raised by built-in function <a class="reference internal" href="functions.html#next" title="next"><code class="xref py py-func docutils literal notranslate"><span class="pre">next()</span></code></a> and an <a class="reference internal" href="../glossary.html#term-iterator"><span class="xref std std-term">iterator</span></a>'s738<a class="reference internal" href="stdtypes.html#iterator.__next__" title="iterator.__next__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__next__()</span></code></a> method to signal that there are no further739items produced by the iterator.</p>740<dl class="py attribute">741<dt class="sig sig-object py" id="StopIteration.value">742<span class="sig-name descname"><span class="pre">value</span></span><a class="headerlink" href="#StopIteration.value" title="Link to this definition">¶</a></dt>743<dd><p>The exception object has a single attribute <code class="xref py py-attr docutils literal notranslate"><span class="pre">value</span></code>, which is744given as an argument when constructing the exception, and defaults745to <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>.</p>746</dd></dl>747 748<p>When a <a class="reference internal" href="../glossary.html#term-generator"><span class="xref std std-term">generator</span></a> or <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> function749returns, a new <code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code> instance is750raised, and the value returned by the function is used as the751<a class="reference internal" href="#StopIteration.value" title="StopIteration.value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">value</span></code></a> parameter to the constructor of the exception.</p>752<p>If a generator code directly or indirectly raises <code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code>,753it is converted into a <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> (retaining the754<code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code> as the new exception’s cause).</p>755<div class="versionchanged">756<p><span class="versionmodified changed">Changed in version 3.3: </span>Added <code class="docutils literal notranslate"><span class="pre">value</span></code> attribute and the ability for generator functions to757use it to return a value.</p>758</div>759<div class="versionchanged">760<p><span class="versionmodified changed">Changed in version 3.5: </span>Introduced the RuntimeError transformation via761<code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">generator_stop</span></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>762</div>763<div class="versionchanged">764<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 <code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code>765error raised in a generator is transformed into a <a class="reference internal" href="#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>.</p>766</div>767</dd></dl>768 769<dl class="py exception">770<dt class="sig sig-object py" id="StopAsyncIteration">771<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">StopAsyncIteration</span></span><a class="headerlink" href="#StopAsyncIteration" title="Link to this definition">¶</a></dt>772<dd><p>Must be raised by <a class="reference internal" href="../reference/datamodel.html#object.__anext__" title="object.__anext__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__anext__()</span></code></a> method of an773<a class="reference internal" href="../glossary.html#term-asynchronous-iterator"><span class="xref std std-term">asynchronous iterator</span></a> object to stop the iteration.</p>774<div class="versionadded">775<p><span class="versionmodified added">Added in version 3.5.</span></p>776</div>777</dd></dl>778 779<dl class="py exception">780<dt class="sig sig-object py" id="SyntaxError">781<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">SyntaxError</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">message</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">details</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#SyntaxError" title="Link to this definition">¶</a></dt>782<dd><p>Raised when the parser encounters a syntax error. This may occur in an783<a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> statement, in a call to the built-in functions784<a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a>, <a class="reference internal" href="functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a>,785or <a class="reference internal" href="functions.html#eval" title="eval"><code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code></a>, or when reading the initial script or standard input786(also interactively).</p>787<p>The <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a> of the exception instance returns only the error message.788Details is a tuple whose members are also available as separate attributes.</p>789<dl class="py attribute">790<dt class="sig sig-object py" id="SyntaxError.filename">791<span class="sig-name descname"><span class="pre">filename</span></span><a class="headerlink" href="#SyntaxError.filename" title="Link to this definition">¶</a></dt>792<dd><p>The name of the file the syntax error occurred in.</p>793</dd></dl>794 795<dl class="py attribute">796<dt class="sig sig-object py" id="SyntaxError.lineno">797<span class="sig-name descname"><span class="pre">lineno</span></span><a class="headerlink" href="#SyntaxError.lineno" title="Link to this definition">¶</a></dt>798<dd><p>Which line number in the file the error occurred in. This is7991-indexed: the first line in the file has a <code class="docutils literal notranslate"><span class="pre">lineno</span></code> of 1.</p>800</dd></dl>801 802<dl class="py attribute">803<dt class="sig sig-object py" id="SyntaxError.offset">804<span class="sig-name descname"><span class="pre">offset</span></span><a class="headerlink" href="#SyntaxError.offset" title="Link to this definition">¶</a></dt>805<dd><p>The column in the line where the error occurred. This is8061-indexed: the first character in the line has an <code class="docutils literal notranslate"><span class="pre">offset</span></code> of 1.</p>807</dd></dl>808 809<dl class="py attribute">810<dt class="sig sig-object py" id="SyntaxError.text">811<span class="sig-name descname"><span class="pre">text</span></span><a class="headerlink" href="#SyntaxError.text" title="Link to this definition">¶</a></dt>812<dd><p>The source code text involved in the error.</p>813</dd></dl>814 815<dl class="py attribute">816<dt class="sig sig-object py" id="SyntaxError.end_lineno">817<span class="sig-name descname"><span class="pre">end_lineno</span></span><a class="headerlink" href="#SyntaxError.end_lineno" title="Link to this definition">¶</a></dt>818<dd><p>Which line number in the file the error occurred ends in. This is8191-indexed: the first line in the file has a <code class="docutils literal notranslate"><span class="pre">lineno</span></code> of 1.</p>820</dd></dl>821 822<dl class="py attribute">823<dt class="sig sig-object py" id="SyntaxError.end_offset">824<span class="sig-name descname"><span class="pre">end_offset</span></span><a class="headerlink" href="#SyntaxError.end_offset" title="Link to this definition">¶</a></dt>825<dd><p>The column in the end line where the error occurred finishes. This is8261-indexed: the first character in the line has an <code class="docutils literal notranslate"><span class="pre">offset</span></code> of 1.</p>827</dd></dl>828 829<p>For errors in f-string fields, the message is prefixed by “f-string: ”830and the offsets are offsets in a text constructed from the replacement831expression. For example, compiling f’Bad {a b} field’ results in this832args attribute: (‘f-string: …’, (‘’, 1, 2, ‘(a b)n’, 1, 5)).</p>833<div class="versionchanged">834<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 class="xref py py-attr docutils literal notranslate"><span class="pre">end_lineno</span></code></a> and <a class="reference internal" href="#SyntaxError.end_offset" title="SyntaxError.end_offset"><code class="xref py py-attr docutils literal notranslate"><span class="pre">end_offset</span></code></a> attributes.</p>835</div>836</dd></dl>837 838<dl class="py exception">839<dt class="sig sig-object py" id="IndentationError">840<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">IndentationError</span></span><a class="headerlink" href="#IndentationError" title="Link to this definition">¶</a></dt>841<dd><p>Base class for syntax errors related to incorrect indentation. This is a842subclass of <a class="reference internal" href="#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>.</p>843</dd></dl>844 845<dl class="py exception">846<dt class="sig sig-object py" id="TabError">847<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">TabError</span></span><a class="headerlink" href="#TabError" title="Link to this definition">¶</a></dt>848<dd><p>Raised when indentation contains an inconsistent use of tabs and spaces.849This is a subclass of <a class="reference internal" href="#IndentationError" title="IndentationError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndentationError</span></code></a>.</p>850</dd></dl>851 852<dl class="py exception">853<dt class="sig sig-object py" id="SystemError">854<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">SystemError</span></span><a class="headerlink" href="#SystemError" title="Link to this definition">¶</a></dt>855<dd><p>Raised when the interpreter finds an internal error, but the situation does not856look so serious to cause it to abandon all hope. The associated value is a857string indicating what went wrong (in low-level terms). In <a class="reference internal" href="../glossary.html#term-CPython"><span class="xref std std-term">CPython</span></a>,858this could be raised by incorrectly using Python’s C API, such as returning859a <code class="docutils literal notranslate"><span class="pre">NULL</span></code> value without an exception set.</p>860<p>If you’re confident that this exception wasn’t your fault, or the fault of861a package you’re using, you should report this to the author or maintainer862of your Python interpreter.863Be sure to report the version of the Python interpreter (<code class="docutils literal notranslate"><span class="pre">sys.version</span></code>; it is864also printed at the start of an interactive Python session), the exact error865message (the exception’s associated value) and if possible the source of the866program that triggered the error.</p>867</dd></dl>868 869<dl class="py exception">870<dt class="sig sig-object py" id="SystemExit">871<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">SystemExit</span></span><a class="headerlink" href="#SystemExit" title="Link to this definition">¶</a></dt>872<dd><p>This exception is raised by the <a class="reference internal" href="sys.html#sys.exit" title="sys.exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exit()</span></code></a> function. It inherits from873<a class="reference internal" href="#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a> instead of <a class="reference internal" href="#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a> so that it is not accidentally874caught by code that catches <code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code>. This allows the exception to875properly propagate up and cause the interpreter to exit. When it is not876handled, the Python interpreter exits; no stack traceback is printed. The877constructor accepts the same optional argument passed to <code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exit()</span></code>.878If the value is an integer, it specifies the system exit status (passed to879C’s <code class="xref c c-func docutils literal notranslate"><span class="pre">exit()</span></code> function); if it is <code class="docutils literal notranslate"><span class="pre">None</span></code>, the exit status is zero; if880it has another type (such as a string), the object’s value is printed and881the exit status is one.</p>882<p>A call to <a class="reference internal" href="sys.html#sys.exit" title="sys.exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exit()</span></code></a> is translated into an exception so that clean-up883handlers (<a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">finally</span></code></a> clauses of <a class="reference internal" href="../reference/compound_stmts.html#try"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">try</span></code></a> statements) can be884executed, and so that a debugger can execute a script without running the risk885of losing control. The <a class="reference internal" href="os.html#os._exit" title="os._exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">os._exit()</span></code></a> function can be used if it is886absolutely positively necessary to exit immediately (for example, in the child887process after a call to <a class="reference internal" href="os.html#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fork()</span></code></a>).</p>888<dl class="py attribute">889<dt class="sig sig-object py" id="SystemExit.code">890<span class="sig-name descname"><span class="pre">code</span></span><a class="headerlink" href="#SystemExit.code" title="Link to this definition">¶</a></dt>891<dd><p>The exit status or error message that is passed to the constructor.892(Defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code>.)</p>893</dd></dl>894 895</dd></dl>896 897<dl class="py exception">898<dt class="sig sig-object py" id="TypeError">899<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">TypeError</span></span><a class="headerlink" href="#TypeError" title="Link to this definition">¶</a></dt>900<dd><p>Raised when an operation or function is applied to an object of inappropriate901type. The associated value is a string giving details about the type mismatch.</p>902<p>This exception may be raised by user code to indicate that an attempted903operation on an object is not supported, and is not meant to be. If an object904is meant to support a given operation but has not yet provided an905implementation, <a class="reference internal" href="#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> is the proper exception to raise.</p>906<p>Passing arguments of the wrong type (e.g. passing a <a class="reference internal" href="stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> when an907<a class="reference internal" href="functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> is expected) should result in a <code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code>, but passing908arguments with the wrong value (e.g. a number outside expected boundaries)909should result in a <a class="reference internal" href="#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>.</p>910</dd></dl>911 912<dl class="py exception">913<dt class="sig sig-object py" id="UnboundLocalError">914<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">UnboundLocalError</span></span><a class="headerlink" href="#UnboundLocalError" title="Link to this definition">¶</a></dt>915<dd><p>Raised when a reference is made to a local variable in a function or method, but916no value has been bound to that variable. This is a subclass of917<a class="reference internal" href="#NameError" title="NameError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NameError</span></code></a>.</p>918</dd></dl>919 920<dl class="py exception">921<dt class="sig sig-object py" id="UnicodeError">922<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">UnicodeError</span></span><a class="headerlink" href="#UnicodeError" title="Link to this definition">¶</a></dt>923<dd><p>Raised when a Unicode-related encoding or decoding error occurs. It is a924subclass of <a class="reference internal" href="#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>.</p>925<p><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeError</span></code> has attributes that describe the encoding or decoding926error. For example, <code class="docutils literal notranslate"><span class="pre">err.object[err.start:err.end]</span></code> gives the particular927invalid input that the codec failed on.</p>928<dl class="py attribute">929<dt class="sig sig-object py" id="UnicodeError.encoding">930<span class="sig-name descname"><span class="pre">encoding</span></span><a class="headerlink" href="#UnicodeError.encoding" title="Link to this definition">¶</a></dt>931<dd><p>The name of the encoding that raised the error.</p>932</dd></dl>933 934<dl class="py attribute">935<dt class="sig sig-object py" id="UnicodeError.reason">936<span class="sig-name descname"><span class="pre">reason</span></span><a class="headerlink" href="#UnicodeError.reason" title="Link to this definition">¶</a></dt>937<dd><p>A string describing the specific codec error.</p>938</dd></dl>939 940<dl class="py attribute">941<dt class="sig sig-object py" id="UnicodeError.object">942<span class="sig-name descname"><span class="pre">object</span></span><a class="headerlink" href="#UnicodeError.object" title="Link to this definition">¶</a></dt>943<dd><p>The object the codec was attempting to encode or decode.</p>944</dd></dl>945 946<dl class="py attribute">947<dt class="sig sig-object py" id="UnicodeError.start">948<span class="sig-name descname"><span class="pre">start</span></span><a class="headerlink" href="#UnicodeError.start" title="Link to this definition">¶</a></dt>949<dd><p>The first index of invalid data in <a class="reference internal" href="functions.html#object" title="object"><code class="xref py py-attr docutils literal notranslate"><span class="pre">object</span></code></a>.</p>950<p>This value should not be negative as it is interpreted as an951absolute offset but this constraint is not enforced at runtime.</p>952</dd></dl>953 954<dl class="py attribute">955<dt class="sig sig-object py" id="UnicodeError.end">956<span class="sig-name descname"><span class="pre">end</span></span><a class="headerlink" href="#UnicodeError.end" title="Link to this definition">¶</a></dt>957<dd><p>The index after the last invalid data in <a class="reference internal" href="functions.html#object" title="object"><code class="xref py py-attr docutils literal notranslate"><span class="pre">object</span></code></a>.</p>958<p>This value should not be negative as it is interpreted as an959absolute offset but this constraint is not enforced at runtime.</p>960</dd></dl>961 962</dd></dl>963 964<dl class="py exception">965<dt class="sig sig-object py" id="UnicodeEncodeError">966<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">UnicodeEncodeError</span></span><a class="headerlink" href="#UnicodeEncodeError" title="Link to this definition">¶</a></dt>967<dd><p>Raised when a Unicode-related error occurs during encoding. It is a subclass of968<a class="reference internal" href="#UnicodeError" title="UnicodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeError</span></code></a>.</p>969</dd></dl>970 971<dl class="py exception">972<dt class="sig sig-object py" id="UnicodeDecodeError">973<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">UnicodeDecodeError</span></span><a class="headerlink" href="#UnicodeDecodeError" title="Link to this definition">¶</a></dt>974<dd><p>Raised when a Unicode-related error occurs during decoding. It is a subclass of975<a class="reference internal" href="#UnicodeError" title="UnicodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeError</span></code></a>.</p>976</dd></dl>977 978<dl class="py exception">979<dt class="sig sig-object py" id="UnicodeTranslateError">980<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">UnicodeTranslateError</span></span><a class="headerlink" href="#UnicodeTranslateError" title="Link to this definition">¶</a></dt>981<dd><p>Raised when a Unicode-related error occurs during translating. It is a subclass982of <a class="reference internal" href="#UnicodeError" title="UnicodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeError</span></code></a>.</p>983</dd></dl>984 985<dl class="py exception">986<dt class="sig sig-object py" id="ValueError">987<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ValueError</span></span><a class="headerlink" href="#ValueError" title="Link to this definition">¶</a></dt>988<dd><p>Raised when an operation or function receives an argument that has the989right type but an inappropriate value, and the situation is not described by a990more precise exception such as <a class="reference internal" href="#IndexError" title="IndexError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndexError</span></code></a>.</p>991</dd></dl>992 993<dl class="py exception">994<dt class="sig sig-object py" id="ZeroDivisionError">995<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ZeroDivisionError</span></span><a class="headerlink" href="#ZeroDivisionError" title="Link to this definition">¶</a></dt>996<dd><p>Raised when the second argument of a division or modulo operation is zero. The997associated value is a string indicating the type of the operands and the998operation.</p>999</dd></dl>1000 1001<p>The following exceptions are kept for compatibility with previous versions;1002starting from Python 3.3, they are aliases of <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>.</p>1003<dl class="py exception">1004<dt class="sig sig-object py" id="EnvironmentError">1005<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">EnvironmentError</span></span><a class="headerlink" href="#EnvironmentError" title="Link to this definition">¶</a></dt>1006<dd></dd></dl>1007 1008<dl class="py exception">1009<dt class="sig sig-object py" id="IOError">1010<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">IOError</span></span><a class="headerlink" href="#IOError" title="Link to this definition">¶</a></dt>1011<dd></dd></dl>1012 1013<dl class="py exception">1014<dt class="sig sig-object py" id="WindowsError">1015<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">WindowsError</span></span><a class="headerlink" href="#WindowsError" title="Link to this definition">¶</a></dt>1016<dd><p>Only available on Windows.</p>1017</dd></dl>1018 1019<section id="os-exceptions">1020<h3>OS exceptions<a class="headerlink" href="#os-exceptions" title="Link to this heading">¶</a></h3>1021<p>The following exceptions are subclasses of <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>, they get raised1022depending on the system error code.</p>1023<dl class="py exception">1024<dt class="sig sig-object py" id="BlockingIOError">1025<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">BlockingIOError</span></span><a class="headerlink" href="#BlockingIOError" title="Link to this definition">¶</a></dt>1026<dd><p>Raised when an operation would block on an object (e.g. socket) set1027for non-blocking operation.1028Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.EAGAIN" title="errno.EAGAIN"><code class="xref py py-const docutils literal notranslate"><span class="pre">EAGAIN</span></code></a>, <a class="reference internal" href="errno.html#errno.EALREADY" title="errno.EALREADY"><code class="xref py py-const docutils literal notranslate"><span class="pre">EALREADY</span></code></a>,1029<a class="reference internal" href="errno.html#errno.EWOULDBLOCK" title="errno.EWOULDBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">EWOULDBLOCK</span></code></a> and <a class="reference internal" href="errno.html#errno.EINPROGRESS" title="errno.EINPROGRESS"><code class="xref py py-const docutils literal notranslate"><span class="pre">EINPROGRESS</span></code></a>.</p>1030<p>In addition to those of <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>, <code class="xref py py-exc docutils literal notranslate"><span class="pre">BlockingIOError</span></code> can have1031one more attribute:</p>1032<dl class="py attribute">1033<dt class="sig sig-object py" id="BlockingIOError.characters_written">1034<span class="sig-name descname"><span class="pre">characters_written</span></span><a class="headerlink" href="#BlockingIOError.characters_written" title="Link to this definition">¶</a></dt>1035<dd><p>An integer containing the number of <strong>bytes</strong> written to the stream1036before it blocked. This attribute is available when using the1037buffered I/O classes from the <a class="reference internal" href="io.html#module-io" title="io: Core tools for working with streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code></a> module.</p>1038</dd></dl>1039 1040</dd></dl>1041 1042<dl class="py exception">1043<dt class="sig sig-object py" id="ChildProcessError">1044<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ChildProcessError</span></span><a class="headerlink" href="#ChildProcessError" title="Link to this definition">¶</a></dt>1045<dd><p>Raised when an operation on a child process failed.1046Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.ECHILD" title="errno.ECHILD"><code class="xref py py-const docutils literal notranslate"><span class="pre">ECHILD</span></code></a>.</p>1047</dd></dl>1048 1049<dl class="py exception">1050<dt class="sig sig-object py" id="ConnectionError">1051<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ConnectionError</span></span><a class="headerlink" href="#ConnectionError" title="Link to this definition">¶</a></dt>1052<dd><p>A base class for connection-related issues.</p>1053<p>Subclasses are <a class="reference internal" href="#BrokenPipeError" title="BrokenPipeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BrokenPipeError</span></code></a>, <a class="reference internal" href="#ConnectionAbortedError" title="ConnectionAbortedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionAbortedError</span></code></a>,1054<a class="reference internal" href="#ConnectionRefusedError" title="ConnectionRefusedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionRefusedError</span></code></a> and <a class="reference internal" href="#ConnectionResetError" title="ConnectionResetError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionResetError</span></code></a>.</p>1055</dd></dl>1056 1057<dl class="py exception">1058<dt class="sig sig-object py" id="BrokenPipeError">1059<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">BrokenPipeError</span></span><a class="headerlink" href="#BrokenPipeError" title="Link to this definition">¶</a></dt>1060<dd><p>A subclass of <a class="reference internal" href="#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a>, raised when trying to write on a1061pipe while the other end has been closed, or trying to write on a socket1062which has been shutdown for writing.1063Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.EPIPE" title="errno.EPIPE"><code class="xref py py-const docutils literal notranslate"><span class="pre">EPIPE</span></code></a> and <a class="reference internal" href="errno.html#errno.ESHUTDOWN" title="errno.ESHUTDOWN"><code class="xref py py-const docutils literal notranslate"><span class="pre">ESHUTDOWN</span></code></a>.</p>1064</dd></dl>1065 1066<dl class="py exception">1067<dt class="sig sig-object py" id="ConnectionAbortedError">1068<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ConnectionAbortedError</span></span><a class="headerlink" href="#ConnectionAbortedError" title="Link to this definition">¶</a></dt>1069<dd><p>A subclass of <a class="reference internal" href="#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a>, raised when a connection attempt1070is aborted by the peer.1071Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.ECONNABORTED" title="errno.ECONNABORTED"><code class="xref py py-const docutils literal notranslate"><span class="pre">ECONNABORTED</span></code></a>.</p>1072</dd></dl>1073 1074<dl class="py exception">1075<dt class="sig sig-object py" id="ConnectionRefusedError">1076<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ConnectionRefusedError</span></span><a class="headerlink" href="#ConnectionRefusedError" title="Link to this definition">¶</a></dt>1077<dd><p>A subclass of <a class="reference internal" href="#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a>, raised when a connection attempt1078is refused by the peer.1079Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.ECONNREFUSED" title="errno.ECONNREFUSED"><code class="xref py py-const docutils literal notranslate"><span class="pre">ECONNREFUSED</span></code></a>.</p>1080</dd></dl>1081 1082<dl class="py exception">1083<dt class="sig sig-object py" id="ConnectionResetError">1084<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ConnectionResetError</span></span><a class="headerlink" href="#ConnectionResetError" title="Link to this definition">¶</a></dt>1085<dd><p>A subclass of <a class="reference internal" href="#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a>, raised when a connection is1086reset by the peer.1087Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.ECONNRESET" title="errno.ECONNRESET"><code class="xref py py-const docutils literal notranslate"><span class="pre">ECONNRESET</span></code></a>.</p>1088</dd></dl>1089 1090<dl class="py exception">1091<dt class="sig sig-object py" id="FileExistsError">1092<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">FileExistsError</span></span><a class="headerlink" href="#FileExistsError" title="Link to this definition">¶</a></dt>1093<dd><p>Raised when trying to create a file or directory which already exists.1094Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.EEXIST" title="errno.EEXIST"><code class="xref py py-const docutils literal notranslate"><span class="pre">EEXIST</span></code></a>.</p>1095</dd></dl>1096 1097<dl class="py exception">1098<dt class="sig sig-object py" id="FileNotFoundError">1099<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">FileNotFoundError</span></span><a class="headerlink" href="#FileNotFoundError" title="Link to this definition">¶</a></dt>1100<dd><p>Raised when a file or directory is requested but doesn’t exist.1101Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.ENOENT" title="errno.ENOENT"><code class="xref py py-const docutils literal notranslate"><span class="pre">ENOENT</span></code></a>.</p>1102</dd></dl>1103 1104<dl class="py exception">1105<dt class="sig sig-object py" id="InterruptedError">1106<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">InterruptedError</span></span><a class="headerlink" href="#InterruptedError" title="Link to this definition">¶</a></dt>1107<dd><p>Raised when a system call is interrupted by an incoming signal.1108Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.EINTR" title="errno.EINTR"><code class="xref py py-const docutils literal notranslate"><span class="pre">EINTR</span></code></a>.</p>1109<div class="versionchanged">1110<p><span class="versionmodified changed">Changed in version 3.5: </span>Python now retries system calls when a syscall is interrupted by a1111signal, 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>1112for the rationale), instead of raising <code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code>.</p>1113</div>1114</dd></dl>1115 1116<dl class="py exception">1117<dt class="sig sig-object py" id="IsADirectoryError">1118<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">IsADirectoryError</span></span><a class="headerlink" href="#IsADirectoryError" title="Link to this definition">¶</a></dt>1119<dd><p>Raised when a file operation (such as <a class="reference internal" href="os.html#os.remove" title="os.remove"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.remove()</span></code></a>) is requested1120on a directory.1121Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.EISDIR" title="errno.EISDIR"><code class="xref py py-const docutils literal notranslate"><span class="pre">EISDIR</span></code></a>.</p>1122</dd></dl>1123 1124<dl class="py exception">1125<dt class="sig sig-object py" id="NotADirectoryError">1126<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">NotADirectoryError</span></span><a class="headerlink" href="#NotADirectoryError" title="Link to this definition">¶</a></dt>1127<dd><p>Raised when a directory operation (such as <a class="reference internal" href="os.html#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listdir()</span></code></a>) is requested on1128something which is not a directory. On most POSIX platforms, it may also be1129raised if an operation attempts to open or traverse a non-directory file as if1130it were a directory.1131Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.ENOTDIR" title="errno.ENOTDIR"><code class="xref py py-const docutils literal notranslate"><span class="pre">ENOTDIR</span></code></a>.</p>1132</dd></dl>1133 1134<dl class="py exception">1135<dt class="sig sig-object py" id="PermissionError">1136<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">PermissionError</span></span><a class="headerlink" href="#PermissionError" title="Link to this definition">¶</a></dt>1137<dd><p>Raised when trying to run an operation without the adequate access1138rights - for example filesystem permissions.1139Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.EACCES" title="errno.EACCES"><code class="xref py py-const docutils literal notranslate"><span class="pre">EACCES</span></code></a>,1140<a class="reference internal" href="errno.html#errno.EPERM" title="errno.EPERM"><code class="xref py py-const docutils literal notranslate"><span class="pre">EPERM</span></code></a>, and <a class="reference internal" href="errno.html#errno.ENOTCAPABLE" title="errno.ENOTCAPABLE"><code class="xref py py-const docutils literal notranslate"><span class="pre">ENOTCAPABLE</span></code></a>.</p>1141<div class="versionchanged">1142<p><span class="versionmodified changed">Changed in version 3.11.1: </span>WASI’s <a class="reference internal" href="errno.html#errno.ENOTCAPABLE" title="errno.ENOTCAPABLE"><code class="xref py py-const docutils literal notranslate"><span class="pre">ENOTCAPABLE</span></code></a> is now mapped to1143<code class="xref py py-exc docutils literal notranslate"><span class="pre">PermissionError</span></code>.</p>1144</div>1145</dd></dl>1146 1147<dl class="py exception">1148<dt class="sig sig-object py" id="ProcessLookupError">1149<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">ProcessLookupError</span></span><a class="headerlink" href="#ProcessLookupError" title="Link to this definition">¶</a></dt>1150<dd><p>Raised when a given process doesn’t exist.1151Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.ESRCH" title="errno.ESRCH"><code class="xref py py-const docutils literal notranslate"><span class="pre">ESRCH</span></code></a>.</p>1152</dd></dl>1153 1154<dl class="py exception">1155<dt class="sig sig-object py" id="TimeoutError">1156<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">TimeoutError</span></span><a class="headerlink" href="#TimeoutError" title="Link to this definition">¶</a></dt>1157<dd><p>Raised when a system function timed out at the system level.1158Corresponds to <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> <a class="reference internal" href="errno.html#errno.ETIMEDOUT" title="errno.ETIMEDOUT"><code class="xref py py-const docutils literal notranslate"><span class="pre">ETIMEDOUT</span></code></a>.</p>1159</dd></dl>1160 1161<div class="versionadded">1162<p><span class="versionmodified added">Added in version 3.3: </span>All the above <a class="reference internal" href="#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> subclasses were added.</p>1163</div>1164<div class="admonition seealso">1165<p class="admonition-title">See also</p>1166<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>1167</div>1168</section>1169</section>1170<section id="warnings">1171<span id="warning-categories-as-exceptions"></span><h2>Warnings<a class="headerlink" href="#warnings" title="Link to this heading">¶</a></h2>1172<p>The following exceptions are used as warning categories; see the1173<a class="reference internal" href="warnings.html#warning-categories"><span class="std std-ref">Warning Categories</span></a> documentation for more details.</p>1174<dl class="py exception">1175<dt class="sig sig-object py" id="Warning">1176<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">Warning</span></span><a class="headerlink" href="#Warning" title="Link to this definition">¶</a></dt>1177<dd><p>Base class for warning categories.</p>1178</dd></dl>1179 1180<dl class="py exception">1181<dt class="sig sig-object py" id="UserWarning">1182<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">UserWarning</span></span><a class="headerlink" href="#UserWarning" title="Link to this definition">¶</a></dt>1183<dd><p>Base class for warnings generated by user code.</p>1184</dd></dl>1185 1186<dl class="py exception">1187<dt class="sig sig-object py" id="DeprecationWarning">1188<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">DeprecationWarning</span></span><a class="headerlink" href="#DeprecationWarning" title="Link to this definition">¶</a></dt>1189<dd><p>Base class for warnings about deprecated features when those warnings are1190intended for other Python developers.</p>1191<p>Ignored by the default warning filters, except in the <code class="docutils literal notranslate"><span class="pre">__main__</span></code> module1192(<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.html#devmode"><span class="std std-ref">Python Development Mode</span></a> shows1193this warning.</p>1194<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>1195</dd></dl>1196 1197<dl class="py exception">1198<dt class="sig sig-object py" id="PendingDeprecationWarning">1199<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">PendingDeprecationWarning</span></span><a class="headerlink" href="#PendingDeprecationWarning" title="Link to this definition">¶</a></dt>1200<dd><p>Base class for warnings about features which are obsolete and