gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1715 line
207KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="Exception Handling" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/c-api/exceptions.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="The functions described in this chapter will let you handle and raise Python exceptions. It is important to understand some of the basics of Python exception handling. It works somewhat like the PO..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="The functions described in this chapter will let you handle and raise Python exceptions. It is important to understand some of the basics of Python exception handling. It works somewhat like the PO..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>Exception Handling &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="Utilities" href="utilities.html" />
  33. <link rel="prev" title="Reference Counting" href="refcounting.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/c-api/exceptions.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <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>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#">Exception Handling</a><ul>
  86. <li><a class="reference internal" href="#printing-and-clearing">Printing and clearing</a></li>
  87. <li><a class="reference internal" href="#raising-exceptions">Raising exceptions</a></li>
  88. <li><a class="reference internal" href="#issuing-warnings">Issuing warnings</a></li>
  89. <li><a class="reference internal" href="#querying-the-error-indicator">Querying the error indicator</a></li>
  90. <li><a class="reference internal" href="#signal-handling">Signal Handling</a></li>
  91. <li><a class="reference internal" href="#exception-classes">Exception Classes</a></li>
  92. <li><a class="reference internal" href="#exception-objects">Exception Objects</a></li>
  93. <li><a class="reference internal" href="#unicode-exception-objects">Unicode Exception Objects</a></li>
  94. <li><a class="reference internal" href="#recursion-control">Recursion Control</a></li>
  95. <li><a class="reference internal" href="#standard-exceptions">Standard Exceptions</a></li>
  96. <li><a class="reference internal" href="#standard-warning-categories">Standard Warning Categories</a></li>
  97. </ul>
  98. </li>
  99. </ul>
  100. </div>
  101. <div>
  102. <h4>Previous topic</h4>
  103. <p class="topless"><a href="refcounting.html"
  104. title="previous chapter">Reference Counting</a></p>
  105. </div>
  106. <div>
  107. <h4>Next topic</h4>
  108. <p class="topless"><a href="utilities.html"
  109. title="next chapter">Utilities</a></p>
  110. </div>
  111. <div role="note" aria-label="source link">
  112. <h3>This Page</h3>
  113. <ul class="this-page-menu">
  114. <li><a href="../bugs.html">Report a Bug</a></li>
  115. <li>
  116. <a href="https://github.com/python/cpython/blob/main/Doc/c-api/exceptions.rst"
  117. rel="nofollow">Show Source
  118. </a>
  119. </li>
  120. </ul>
  121. </div>
  122. </nav>
  123. </div>
  124. </div>
  125. <div class="related" role="navigation" aria-label="related navigation">
  126. <h3>Navigation</h3>
  127. <ul>
  128. <li class="right" style="margin-right: 10px">
  129. <a href="../genindex.html" title="General Index"
  130. accesskey="I">index</a></li>
  131. <li class="right" >
  132. <a href="../py-modindex.html" title="Python Module Index"
  133. >modules</a> |</li>
  134. <li class="right" >
  135. <a href="utilities.html" title="Utilities"
  136. accesskey="N">next</a> |</li>
  137. <li class="right" >
  138. <a href="refcounting.html" title="Reference Counting"
  139. accesskey="P">previous</a> |</li>
  140. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  141. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  142. <li class="switchers">
  143. <div class="language_switcher_placeholder"></div>
  144. <div class="version_switcher_placeholder"></div>
  145. </li>
  146. <li>
  147. </li>
  148. <li id="cpython-language-and-version">
  149. <a href="../index.html">3.12.3 Documentation</a> &#187;
  150. </li>
  151. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python/C API Reference Manual</a> &#187;</li>
  152. <li class="nav-item nav-item-this"><a href="">Exception Handling</a></li>
  153. <li class="right">
  154. <div class="inline-search" role="search">
  155. <form class="inline-search" action="../search.html" method="get">
  156. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  157. <input type="submit" value="Go" />
  158. </form>
  159. </div>
  160. |
  161. </li>
  162. <li class="right">
  163. <label class="theme-selector-label">
  164. Theme
  165. <select class="theme-selector" oninput="activateTheme(this.value)">
  166. <option value="auto" selected>Auto</option>
  167. <option value="light">Light</option>
  168. <option value="dark">Dark</option>
  169. </select>
  170. </label> |</li>
  171. </ul>
  172. </div>
  173. <div class="document">
  174. <div class="documentwrapper">
  175. <div class="bodywrapper">
  176. <div class="body" role="main">
  177. <section id="exception-handling">
  178. <span id="exceptionhandling"></span><h1>Exception Handling<a class="headerlink" href="#exception-handling" title="Link to this heading">¶</a></h1>
  179. <p>The functions described in this chapter will let you handle and raise Python
  180. exceptions. It is important to understand some of the basics of Python
  181. exception handling. It works somewhat like the POSIX <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> variable:
  182. there is a global indicator (per thread) of the last error that occurred. Most
  183. C API functions don’t clear this on success, but will set it to indicate the
  184. cause of the error on failure. Most C API functions also return an error
  185. indicator, usually <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if they are supposed to return a pointer, or <code class="docutils literal notranslate"><span class="pre">-1</span></code>
  186. if they return an integer (exception: the <code class="docutils literal notranslate"><span class="pre">PyArg_*</span></code> functions
  187. return <code class="docutils literal notranslate"><span class="pre">1</span></code> for success and <code class="docutils literal notranslate"><span class="pre">0</span></code> for failure).</p>
  188. <p>Concretely, the error indicator consists of three object pointers: the
  189. exception’s type, the exception’s value, and the traceback object. Any
  190. of those pointers can be <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if non-set (although some combinations are
  191. forbidden, for example you can’t have a non-<code class="docutils literal notranslate"><span class="pre">NULL</span></code> traceback if the exception
  192. type is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>).</p>
  193. <p>When a function must fail because some function it called failed, it generally
  194. doesn’t set the error indicator; the function it called already set it. It is
  195. responsible for either handling the error and clearing the exception or
  196. returning after cleaning up any resources it holds (such as object references or
  197. memory allocations); it should <em>not</em> continue normally if it is not prepared to
  198. handle the error. If returning due to an error, it is important to indicate to
  199. the caller that an error has been set. If the error is not handled or carefully
  200. propagated, additional calls into the Python/C API may not behave as intended
  201. and may fail in mysterious ways.</p>
  202. <div class="admonition note">
  203. <p class="admonition-title">Note</p>
  204. <p>The error indicator is <strong>not</strong> the result of <a class="reference internal" href="../library/sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a>.
  205. The former corresponds to an exception that is not yet caught (and is
  206. therefore still propagating), while the latter returns an exception after
  207. it is caught (and has therefore stopped propagating).</p>
  208. </div>
  209. <section id="printing-and-clearing">
  210. <h2>Printing and clearing<a class="headerlink" href="#printing-and-clearing" title="Link to this heading">¶</a></h2>
  211. <dl class="c function">
  212. <dt class="sig sig-object c" id="c.PyErr_Clear">
  213. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_Clear</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_Clear" title="Link to this definition">¶</a><br /></dt>
  214. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Clear the error indicator. If the error indicator is not set, there is no
  215. effect.</p>
  216. </dd></dl>
  217. <dl class="c function">
  218. <dt class="sig sig-object c" id="c.PyErr_PrintEx">
  219. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_PrintEx</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">set_sys_last_vars</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_PrintEx" title="Link to this definition">¶</a><br /></dt>
  220. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Print a standard traceback to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> and clear the error indicator.
  221. <strong>Unless</strong> the error is a <code class="docutils literal notranslate"><span class="pre">SystemExit</span></code>, in that case no traceback is
  222. printed and the Python process will exit with the error code specified by
  223. the <code class="docutils literal notranslate"><span class="pre">SystemExit</span></code> instance.</p>
  224. <p>Call this function <strong>only</strong> when the error indicator is set. Otherwise it
  225. will cause a fatal error!</p>
  226. <p>If <em>set_sys_last_vars</em> is nonzero, the variable <a class="reference internal" href="../library/sys.html#sys.last_exc" title="sys.last_exc"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_exc</span></code></a> is
  227. set to the printed exception. For backwards compatibility, the
  228. deprecated variables <a class="reference internal" href="../library/sys.html#sys.last_type" title="sys.last_type"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_type</span></code></a>, <a class="reference internal" href="../library/sys.html#sys.last_value" title="sys.last_value"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_value</span></code></a> and
  229. <a class="reference internal" href="../library/sys.html#sys.last_traceback" title="sys.last_traceback"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_traceback</span></code></a> are also set to the type, value and traceback
  230. of this exception, respectively.</p>
  231. <div class="versionchanged">
  232. <p><span class="versionmodified changed">Changed in version 3.12: </span>The setting of <a class="reference internal" href="../library/sys.html#sys.last_exc" title="sys.last_exc"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_exc</span></code></a> was added.</p>
  233. </div>
  234. </dd></dl>
  235. <dl class="c function">
  236. <dt class="sig sig-object c" id="c.PyErr_Print">
  237. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_Print</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_Print" title="Link to this definition">¶</a><br /></dt>
  238. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Alias for <code class="docutils literal notranslate"><span class="pre">PyErr_PrintEx(1)</span></code>.</p>
  239. </dd></dl>
  240. <dl class="c function">
  241. <dt class="sig sig-object c" id="c.PyErr_WriteUnraisable">
  242. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_WriteUnraisable</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">obj</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_WriteUnraisable" title="Link to this definition">¶</a><br /></dt>
  243. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Call <a class="reference internal" href="../library/sys.html#sys.unraisablehook" title="sys.unraisablehook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.unraisablehook()</span></code></a> using the current exception and <em>obj</em>
  244. argument.</p>
  245. <p>This utility function prints a warning message to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> when an
  246. exception has been set but it is impossible for the interpreter to actually
  247. raise the exception. It is used, for example, when an exception occurs in an
  248. <a class="reference internal" href="../reference/datamodel.html#object.__del__" title="object.__del__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__del__()</span></code></a> method.</p>
  249. <p>The function is called with a single argument <em>obj</em> that identifies the context
  250. in which the unraisable exception occurred. If possible,
  251. the repr of <em>obj</em> will be printed in the warning message.
  252. If <em>obj</em> is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, only the traceback is printed.</p>
  253. <p>An exception must be set when calling this function.</p>
  254. <div class="versionchanged">
  255. <p><span class="versionmodified changed">Changed in version 3.4: </span>Print a traceback. Print only traceback if <em>obj</em> is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  256. </div>
  257. <div class="versionchanged">
  258. <p><span class="versionmodified changed">Changed in version 3.8: </span>Use <a class="reference internal" href="../library/sys.html#sys.unraisablehook" title="sys.unraisablehook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.unraisablehook()</span></code></a>.</p>
  259. </div>
  260. </dd></dl>
  261. <dl class="c function">
  262. <dt class="sig sig-object c" id="c.PyErr_DisplayException">
  263. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_DisplayException</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_DisplayException" title="Link to this definition">¶</a><br /></dt>
  264. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.12.</em><p>Print the standard traceback display of <code class="docutils literal notranslate"><span class="pre">exc</span></code> to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>, including
  265. chained exceptions and notes.</p>
  266. <div class="versionadded">
  267. <p><span class="versionmodified added">New in version 3.12.</span></p>
  268. </div>
  269. </dd></dl>
  270. </section>
  271. <section id="raising-exceptions">
  272. <h2>Raising exceptions<a class="headerlink" href="#raising-exceptions" title="Link to this heading">¶</a></h2>
  273. <p>These functions help you set the current thread’s error indicator.
  274. For convenience, some of these functions will always return a
  275. <code class="docutils literal notranslate"><span class="pre">NULL</span></code> pointer for use in a <code class="docutils literal notranslate"><span class="pre">return</span></code> statement.</p>
  276. <dl class="c function">
  277. <dt class="sig sig-object c" id="c.PyErr_SetString">
  278. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetString</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">message</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetString" title="Link to this definition">¶</a><br /></dt>
  279. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>This is the most common way to set the error indicator. The first argument
  280. specifies the exception type; it is normally one of the standard exceptions,
  281. e.g. <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_RuntimeError</span></code>. You need not create a new
  282. <a class="reference internal" href="../glossary.html#term-strong-reference"><span class="xref std std-term">strong reference</span></a> to it (e.g. with <a class="reference internal" href="refcounting.html#c.Py_INCREF" title="Py_INCREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_INCREF()</span></code></a>).
  283. The second argument is an error message; it is decoded from <code class="docutils literal notranslate"><span class="pre">'utf-8'</span></code>.</p>
  284. </dd></dl>
  285. <dl class="c function">
  286. <dt class="sig sig-object c" id="c.PyErr_SetObject">
  287. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetObject</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">value</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetObject" title="Link to this definition">¶</a><br /></dt>
  288. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>This function is similar to <a class="reference internal" href="#c.PyErr_SetString" title="PyErr_SetString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetString()</span></code></a> but lets you specify an
  289. arbitrary Python object for the “value” of the exception.</p>
  290. </dd></dl>
  291. <dl class="c function">
  292. <dt class="sig sig-object c" id="c.PyErr_Format">
  293. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_Format</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exception</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">format</span></span>, <span class="p"><span class="pre">...</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_Format" title="Link to this definition">¶</a><br /></dt>
  294. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>This function sets the error indicator and returns <code class="docutils literal notranslate"><span class="pre">NULL</span></code>. <em>exception</em>
  295. should be a Python exception class. The <em>format</em> and subsequent
  296. parameters help format the error message; they have the same meaning and
  297. values as in <a class="reference internal" href="unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a>. <em>format</em> is an ASCII-encoded
  298. string.</p>
  299. </dd></dl>
  300. <dl class="c function">
  301. <dt class="sig sig-object c" id="c.PyErr_FormatV">
  302. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_FormatV</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exception</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">format</span></span>, <span class="n"><span class="pre">va_list</span></span><span class="w"> </span><span class="n"><span class="pre">vargs</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_FormatV" title="Link to this definition">¶</a><br /></dt>
  303. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.5.</em><p>Same as <a class="reference internal" href="#c.PyErr_Format" title="PyErr_Format"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Format()</span></code></a>, but taking a <code class="xref c c-type docutils literal notranslate"><span class="pre">va_list</span></code> argument rather
  304. than a variable number of arguments.</p>
  305. <div class="versionadded">
  306. <p><span class="versionmodified added">New in version 3.5.</span></p>
  307. </div>
  308. </dd></dl>
  309. <dl class="c function">
  310. <dt class="sig sig-object c" id="c.PyErr_SetNone">
  311. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetNone</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetNone" title="Link to this definition">¶</a><br /></dt>
  312. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>This is a shorthand for <code class="docutils literal notranslate"><span class="pre">PyErr_SetObject(type,</span> <span class="pre">Py_None)</span></code>.</p>
  313. </dd></dl>
  314. <dl class="c function">
  315. <dt class="sig sig-object c" id="c.PyErr_BadArgument">
  316. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_BadArgument</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_BadArgument" title="Link to this definition">¶</a><br /></dt>
  317. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>This is a shorthand for <code class="docutils literal notranslate"><span class="pre">PyErr_SetString(PyExc_TypeError,</span> <span class="pre">message)</span></code>, where
  318. <em>message</em> indicates that a built-in operation was invoked with an illegal
  319. argument. It is mostly for internal use.</p>
  320. </dd></dl>
  321. <dl class="c function">
  322. <dt class="sig sig-object c" id="c.PyErr_NoMemory">
  323. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_NoMemory</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_NoMemory" title="Link to this definition">¶</a><br /></dt>
  324. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>This is a shorthand for <code class="docutils literal notranslate"><span class="pre">PyErr_SetNone(PyExc_MemoryError)</span></code>; it returns <code class="docutils literal notranslate"><span class="pre">NULL</span></code>
  325. so an object allocation function can write <code class="docutils literal notranslate"><span class="pre">return</span> <span class="pre">PyErr_NoMemory();</span></code> when it
  326. runs out of memory.</p>
  327. </dd></dl>
  328. <dl class="c function">
  329. <dt class="sig sig-object c" id="c.PyErr_SetFromErrno">
  330. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetFromErrno</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetFromErrno" title="Link to this definition">¶</a><br /></dt>
  331. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p id="index-0">This is a convenience function to raise an exception when a C library function
  332. has returned an error and set the C variable <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code>. It constructs a
  333. tuple object whose first item is the integer <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> value and whose
  334. second item is the corresponding error message (gotten from <code class="xref c c-func docutils literal notranslate"><span class="pre">strerror()</span></code>),
  335. and then calls <code class="docutils literal notranslate"><span class="pre">PyErr_SetObject(type,</span> <span class="pre">object)</span></code>. On Unix, when the
  336. <code class="xref c c-data docutils literal notranslate"><span class="pre">errno</span></code> value is <code class="xref c c-macro docutils literal notranslate"><span class="pre">EINTR</span></code>, indicating an interrupted system call,
  337. this calls <a class="reference internal" href="#c.PyErr_CheckSignals" title="PyErr_CheckSignals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_CheckSignals()</span></code></a>, and if that set the error indicator,
  338. leaves it set to that. The function always returns <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, so a wrapper
  339. function around a system call can write <code class="docutils literal notranslate"><span class="pre">return</span> <span class="pre">PyErr_SetFromErrno(type);</span></code>
  340. when the system call returns an error.</p>
  341. </dd></dl>
  342. <dl class="c function">
  343. <dt class="sig sig-object c" id="c.PyErr_SetFromErrnoWithFilenameObject">
  344. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetFromErrnoWithFilenameObject</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filenameObject</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetFromErrnoWithFilenameObject" title="Link to this definition">¶</a><br /></dt>
  345. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Similar to <a class="reference internal" href="#c.PyErr_SetFromErrno" title="PyErr_SetFromErrno"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetFromErrno()</span></code></a>, with the additional behavior that if
  346. <em>filenameObject</em> is not <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, it is passed to the constructor of <em>type</em> as
  347. a third parameter. In the case of <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> exception,
  348. this is used to define the <code class="xref py py-attr docutils literal notranslate"><span class="pre">filename</span></code> attribute of the
  349. exception instance.</p>
  350. </dd></dl>
  351. <dl class="c function">
  352. <dt class="sig sig-object c" id="c.PyErr_SetFromErrnoWithFilenameObjects">
  353. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetFromErrnoWithFilenameObjects</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filenameObject</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filenameObject2</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetFromErrnoWithFilenameObjects" title="Link to this definition">¶</a><br /></dt>
  354. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.7.</em><p>Similar to <a class="reference internal" href="#c.PyErr_SetFromErrnoWithFilenameObject" title="PyErr_SetFromErrnoWithFilenameObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetFromErrnoWithFilenameObject()</span></code></a>, but takes a second
  355. filename object, for raising errors when a function that takes two filenames
  356. fails.</p>
  357. <div class="versionadded">
  358. <p><span class="versionmodified added">New in version 3.4.</span></p>
  359. </div>
  360. </dd></dl>
  361. <dl class="c function">
  362. <dt class="sig sig-object c" id="c.PyErr_SetFromErrnoWithFilename">
  363. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetFromErrnoWithFilename</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetFromErrnoWithFilename" title="Link to this definition">¶</a><br /></dt>
  364. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Similar to <a class="reference internal" href="#c.PyErr_SetFromErrnoWithFilenameObject" title="PyErr_SetFromErrnoWithFilenameObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetFromErrnoWithFilenameObject()</span></code></a>, but the filename
  365. is given as a C string. <em>filename</em> is decoded from the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem
  366. encoding and error handler</span></a>.</p>
  367. </dd></dl>
  368. <dl class="c function">
  369. <dt class="sig sig-object c" id="c.PyErr_SetFromWindowsErr">
  370. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetFromWindowsErr</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">ierr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetFromWindowsErr" title="Link to this definition">¶</a><br /></dt>
  371. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> on Windows since version 3.7.</em><p>This is a convenience function to raise <a class="reference internal" href="../library/exceptions.html#WindowsError" title="WindowsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">WindowsError</span></code></a>. If called with
  372. <em>ierr</em> of <code class="docutils literal notranslate"><span class="pre">0</span></code>, the error code returned by a call to <code class="xref c c-func docutils literal notranslate"><span class="pre">GetLastError()</span></code>
  373. is used instead. It calls the Win32 function <code class="xref c c-func docutils literal notranslate"><span class="pre">FormatMessage()</span></code> to retrieve
  374. the Windows description of error code given by <em>ierr</em> or <code class="xref c c-func docutils literal notranslate"><span class="pre">GetLastError()</span></code>,
  375. then it constructs a tuple object whose first item is the <em>ierr</em> value and whose
  376. second item is the corresponding error message (gotten from
  377. <code class="xref c c-func docutils literal notranslate"><span class="pre">FormatMessage()</span></code>), and then calls <code class="docutils literal notranslate"><span class="pre">PyErr_SetObject(PyExc_WindowsError,</span>
  378. <span class="pre">object)</span></code>. This function always returns <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  379. <div class="availability docutils container">
  380. <p><a class="reference internal" href="../library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
  381. </div>
  382. </dd></dl>
  383. <dl class="c function">
  384. <dt class="sig sig-object c" id="c.PyErr_SetExcFromWindowsErr">
  385. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetExcFromWindowsErr</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">ierr</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetExcFromWindowsErr" title="Link to this definition">¶</a><br /></dt>
  386. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> on Windows since version 3.7.</em><p>Similar to <a class="reference internal" href="#c.PyErr_SetFromWindowsErr" title="PyErr_SetFromWindowsErr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetFromWindowsErr()</span></code></a>, with an additional parameter
  387. specifying the exception type to be raised.</p>
  388. <div class="availability docutils container">
  389. <p><a class="reference internal" href="../library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
  390. </div>
  391. </dd></dl>
  392. <dl class="c function">
  393. <dt class="sig sig-object c" id="c.PyErr_SetFromWindowsErrWithFilename">
  394. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetFromWindowsErrWithFilename</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">ierr</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetFromWindowsErrWithFilename" title="Link to this definition">¶</a><br /></dt>
  395. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> on Windows since version 3.7.</em><p>Similar to <a class="reference internal" href="#c.PyErr_SetFromWindowsErr" title="PyErr_SetFromWindowsErr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetFromWindowsErr()</span></code></a>, with the additional behavior
  396. that if <em>filename</em> is not <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, it is decoded from the filesystem
  397. encoding (<a class="reference internal" href="../library/os.html#os.fsdecode" title="os.fsdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsdecode()</span></code></a>) and passed to the constructor of
  398. <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> as a third parameter to be used to define the
  399. <code class="xref py py-attr docutils literal notranslate"><span class="pre">filename</span></code> attribute of the exception instance.</p>
  400. <div class="availability docutils container">
  401. <p><a class="reference internal" href="../library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
  402. </div>
  403. </dd></dl>
  404. <dl class="c function">
  405. <dt class="sig sig-object c" id="c.PyErr_SetExcFromWindowsErrWithFilenameObject">
  406. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetExcFromWindowsErrWithFilenameObject</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">ierr</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetExcFromWindowsErrWithFilenameObject" title="Link to this definition">¶</a><br /></dt>
  407. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> on Windows since version 3.7.</em><p>Similar to <a class="reference internal" href="#c.PyErr_SetExcFromWindowsErr" title="PyErr_SetExcFromWindowsErr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetExcFromWindowsErr()</span></code></a>, with the additional behavior
  408. that if <em>filename</em> is not <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, it is passed to the constructor of
  409. <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> as a third parameter to be used to define the
  410. <code class="xref py py-attr docutils literal notranslate"><span class="pre">filename</span></code> attribute of the exception instance.</p>
  411. <div class="availability docutils container">
  412. <p><a class="reference internal" href="../library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
  413. </div>
  414. </dd></dl>
  415. <dl class="c function">
  416. <dt class="sig sig-object c" id="c.PyErr_SetExcFromWindowsErrWithFilenameObjects">
  417. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetExcFromWindowsErrWithFilenameObjects</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">ierr</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename2</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetExcFromWindowsErrWithFilenameObjects" title="Link to this definition">¶</a><br /></dt>
  418. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> on Windows since version 3.7.</em><p>Similar to <a class="reference internal" href="#c.PyErr_SetExcFromWindowsErrWithFilenameObject" title="PyErr_SetExcFromWindowsErrWithFilenameObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetExcFromWindowsErrWithFilenameObject()</span></code></a>,
  419. but accepts a second filename object.</p>
  420. <div class="availability docutils container">
  421. <p><a class="reference internal" href="../library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
  422. </div>
  423. <div class="versionadded">
  424. <p><span class="versionmodified added">New in version 3.4.</span></p>
  425. </div>
  426. </dd></dl>
  427. <dl class="c function">
  428. <dt class="sig sig-object c" id="c.PyErr_SetExcFromWindowsErrWithFilename">
  429. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetExcFromWindowsErrWithFilename</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">ierr</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetExcFromWindowsErrWithFilename" title="Link to this definition">¶</a><br /></dt>
  430. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> on Windows since version 3.7.</em><p>Similar to <a class="reference internal" href="#c.PyErr_SetFromWindowsErrWithFilename" title="PyErr_SetFromWindowsErrWithFilename"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetFromWindowsErrWithFilename()</span></code></a>, with an additional
  431. parameter specifying the exception type to be raised.</p>
  432. <div class="availability docutils container">
  433. <p><a class="reference internal" href="../library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
  434. </div>
  435. </dd></dl>
  436. <dl class="c function">
  437. <dt class="sig sig-object c" id="c.PyErr_SetImportError">
  438. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetImportError</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">msg</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">path</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetImportError" title="Link to this definition">¶</a><br /></dt>
  439. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.7.</em><p>This is a convenience function to raise <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>. <em>msg</em> will be
  440. set as the exception’s message string. <em>name</em> and <em>path</em>, both of which can
  441. be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, will be set as the <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>’s respective <code class="docutils literal notranslate"><span class="pre">name</span></code>
  442. and <code class="docutils literal notranslate"><span class="pre">path</span></code> attributes.</p>
  443. <div class="versionadded">
  444. <p><span class="versionmodified added">New in version 3.3.</span></p>
  445. </div>
  446. </dd></dl>
  447. <dl class="c function">
  448. <dt class="sig sig-object c" id="c.PyErr_SetImportErrorSubclass">
  449. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetImportErrorSubclass</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exception</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">msg</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">path</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetImportErrorSubclass" title="Link to this definition">¶</a><br /></dt>
  450. <dd><em class="refcount">Return value: Always NULL.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.6.</em><p>Much like <a class="reference internal" href="#c.PyErr_SetImportError" title="PyErr_SetImportError"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetImportError()</span></code></a> but this function allows for
  451. specifying a subclass of <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> to raise.</p>
  452. <div class="versionadded">
  453. <p><span class="versionmodified added">New in version 3.6.</span></p>
  454. </div>
  455. </dd></dl>
  456. <dl class="c function">
  457. <dt class="sig sig-object c" id="c.PyErr_SyntaxLocationObject">
  458. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SyntaxLocationObject</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">lineno</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">col_offset</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SyntaxLocationObject" title="Link to this definition">¶</a><br /></dt>
  459. <dd><p>Set file, line, and offset information for the current exception. If the
  460. current exception is not a <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>, then it sets additional
  461. attributes, which make the exception printing subsystem think the exception
  462. is a <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>.</p>
  463. <div class="versionadded">
  464. <p><span class="versionmodified added">New in version 3.4.</span></p>
  465. </div>
  466. </dd></dl>
  467. <dl class="c function">
  468. <dt class="sig sig-object c" id="c.PyErr_SyntaxLocationEx">
  469. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SyntaxLocationEx</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">lineno</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">col_offset</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SyntaxLocationEx" title="Link to this definition">¶</a><br /></dt>
  470. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.7.</em><p>Like <a class="reference internal" href="#c.PyErr_SyntaxLocationObject" title="PyErr_SyntaxLocationObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SyntaxLocationObject()</span></code></a>, but <em>filename</em> is a byte string
  471. decoded from the <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>.</p>
  472. <div class="versionadded">
  473. <p><span class="versionmodified added">New in version 3.2.</span></p>
  474. </div>
  475. </dd></dl>
  476. <dl class="c function">
  477. <dt class="sig sig-object c" id="c.PyErr_SyntaxLocation">
  478. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SyntaxLocation</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">lineno</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SyntaxLocation" title="Link to this definition">¶</a><br /></dt>
  479. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Like <a class="reference internal" href="#c.PyErr_SyntaxLocationEx" title="PyErr_SyntaxLocationEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SyntaxLocationEx()</span></code></a>, but the <em>col_offset</em> parameter is
  480. omitted.</p>
  481. </dd></dl>
  482. <dl class="c function">
  483. <dt class="sig sig-object c" id="c.PyErr_BadInternalCall">
  484. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_BadInternalCall</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_BadInternalCall" title="Link to this definition">¶</a><br /></dt>
  485. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>This is a shorthand for <code class="docutils literal notranslate"><span class="pre">PyErr_SetString(PyExc_SystemError,</span> <span class="pre">message)</span></code>,
  486. where <em>message</em> indicates that an internal operation (e.g. a Python/C API
  487. function) was invoked with an illegal argument. It is mostly for internal
  488. use.</p>
  489. </dd></dl>
  490. </section>
  491. <section id="issuing-warnings">
  492. <h2>Issuing warnings<a class="headerlink" href="#issuing-warnings" title="Link to this heading">¶</a></h2>
  493. <p>Use these functions to issue warnings from C code. They mirror similar
  494. functions exported by the Python <a class="reference internal" href="../library/warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> module. They normally
  495. print a warning message to <em>sys.stderr</em>; however, it is
  496. also possible that the user has specified that warnings are to be turned into
  497. errors, and in that case they will raise an exception. It is also possible that
  498. the functions raise an exception because of a problem with the warning machinery.
  499. The return value is <code class="docutils literal notranslate"><span class="pre">0</span></code> if no exception is raised, or <code class="docutils literal notranslate"><span class="pre">-1</span></code> if an exception
  500. is raised. (It is not possible to determine whether a warning message is
  501. actually printed, nor what the reason is for the exception; this is
  502. intentional.) If an exception is raised, the caller should do its normal
  503. exception handling (for example, <a class="reference internal" href="refcounting.html#c.Py_DECREF" title="Py_DECREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DECREF()</span></code></a> owned references and return
  504. an error value).</p>
  505. <dl class="c function">
  506. <dt class="sig sig-object c" id="c.PyErr_WarnEx">
  507. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_WarnEx</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">category</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">message</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">stack_level</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_WarnEx" title="Link to this definition">¶</a><br /></dt>
  508. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Issue a warning message. The <em>category</em> argument is a warning category (see
  509. below) or <code class="docutils literal notranslate"><span class="pre">NULL</span></code>; the <em>message</em> argument is a UTF-8 encoded string. <em>stack_level</em> is a
  510. positive number giving a number of stack frames; the warning will be issued from
  511. the currently executing line of code in that stack frame. A <em>stack_level</em> of 1
  512. is the function calling <a class="reference internal" href="#c.PyErr_WarnEx" title="PyErr_WarnEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_WarnEx()</span></code></a>, 2 is the function above that,
  513. and so forth.</p>
  514. <p>Warning categories must be subclasses of <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_Warning</span></code>;
  515. <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_Warning</span></code> is a subclass of <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_Exception</span></code>;
  516. the default warning category is <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_RuntimeWarning</span></code>. The standard
  517. Python warning categories are available as global variables whose names are
  518. enumerated at <a class="reference internal" href="#standardwarningcategories"><span class="std std-ref">Standard Warning Categories</span></a>.</p>
  519. <p>For information about warning control, see the documentation for the
  520. <a class="reference internal" href="../library/warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> module and the <a class="reference internal" href="../using/cmdline.html#cmdoption-W"><code class="xref std std-option docutils literal notranslate"><span class="pre">-W</span></code></a> option in the command line
  521. documentation. There is no C API for warning control.</p>
  522. </dd></dl>
  523. <dl class="c function">
  524. <dt class="sig sig-object c" id="c.PyErr_WarnExplicitObject">
  525. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_WarnExplicitObject</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">category</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">message</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">lineno</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">module</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">registry</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_WarnExplicitObject" title="Link to this definition">¶</a><br /></dt>
  526. <dd><p>Issue a warning message with explicit control over all warning attributes. This
  527. is a straightforward wrapper around the Python function
  528. <a class="reference internal" href="../library/warnings.html#warnings.warn_explicit" title="warnings.warn_explicit"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.warn_explicit()</span></code></a>; see there for more information. The <em>module</em>
  529. and <em>registry</em> arguments may be set to <code class="docutils literal notranslate"><span class="pre">NULL</span></code> to get the default effect
  530. described there.</p>
  531. <div class="versionadded">
  532. <p><span class="versionmodified added">New in version 3.4.</span></p>
  533. </div>
  534. </dd></dl>
  535. <dl class="c function">
  536. <dt class="sig sig-object c" id="c.PyErr_WarnExplicit">
  537. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_WarnExplicit</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">category</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">message</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">filename</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">lineno</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">module</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">registry</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_WarnExplicit" title="Link to this definition">¶</a><br /></dt>
  538. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Similar to <a class="reference internal" href="#c.PyErr_WarnExplicitObject" title="PyErr_WarnExplicitObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_WarnExplicitObject()</span></code></a> except that <em>message</em> and
  539. <em>module</em> are UTF-8 encoded strings, and <em>filename</em> is decoded from the
  540. <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>.</p>
  541. </dd></dl>
  542. <dl class="c function">
  543. <dt class="sig sig-object c" id="c.PyErr_WarnFormat">
  544. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_WarnFormat</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">category</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">stack_level</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">format</span></span>, <span class="p"><span class="pre">...</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_WarnFormat" title="Link to this definition">¶</a><br /></dt>
  545. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Function similar to <a class="reference internal" href="#c.PyErr_WarnEx" title="PyErr_WarnEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_WarnEx()</span></code></a>, but use
  546. <a class="reference internal" href="unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a> to format the warning message. <em>format</em> is
  547. an ASCII-encoded string.</p>
  548. <div class="versionadded">
  549. <p><span class="versionmodified added">New in version 3.2.</span></p>
  550. </div>
  551. </dd></dl>
  552. <dl class="c function">
  553. <dt class="sig sig-object c" id="c.PyErr_ResourceWarning">
  554. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_ResourceWarning</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">source</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">stack_level</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">format</span></span>, <span class="p"><span class="pre">...</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_ResourceWarning" title="Link to this definition">¶</a><br /></dt>
  555. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.6.</em><p>Function similar to <a class="reference internal" href="#c.PyErr_WarnFormat" title="PyErr_WarnFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_WarnFormat()</span></code></a>, but <em>category</em> is
  556. <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a> and it passes <em>source</em> to <code class="xref py py-class docutils literal notranslate"><span class="pre">warnings.WarningMessage</span></code>.</p>
  557. <div class="versionadded">
  558. <p><span class="versionmodified added">New in version 3.6.</span></p>
  559. </div>
  560. </dd></dl>
  561. </section>
  562. <section id="querying-the-error-indicator">
  563. <h2>Querying the error indicator<a class="headerlink" href="#querying-the-error-indicator" title="Link to this heading">¶</a></h2>
  564. <dl class="c function">
  565. <dt class="sig sig-object c" id="c.PyErr_Occurred">
  566. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_Occurred</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_Occurred" title="Link to this definition">¶</a><br /></dt>
  567. <dd><em class="refcount">Return value: Borrowed reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Test whether the error indicator is set. If set, return the exception <em>type</em>
  568. (the first argument to the last call to one of the <code class="docutils literal notranslate"><span class="pre">PyErr_Set*</span></code>
  569. functions or to <a class="reference internal" href="#c.PyErr_Restore" title="PyErr_Restore"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Restore()</span></code></a>). If not set, return <code class="docutils literal notranslate"><span class="pre">NULL</span></code>. You do not
  570. own a reference to the return value, so you do not need to <a class="reference internal" href="refcounting.html#c.Py_DECREF" title="Py_DECREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DECREF()</span></code></a>
  571. it.</p>
  572. <p>The caller must hold the GIL.</p>
  573. <div class="admonition note">
  574. <p class="admonition-title">Note</p>
  575. <p>Do not compare the return value to a specific exception; use
  576. <a class="reference internal" href="#c.PyErr_ExceptionMatches" title="PyErr_ExceptionMatches"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_ExceptionMatches()</span></code></a> instead, shown below. (The comparison could
  577. easily fail since the exception may be an instance instead of a class, in the
  578. case of a class exception, or it may be a subclass of the expected exception.)</p>
  579. </div>
  580. </dd></dl>
  581. <dl class="c function">
  582. <dt class="sig sig-object c" id="c.PyErr_ExceptionMatches">
  583. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_ExceptionMatches</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_ExceptionMatches" title="Link to this definition">¶</a><br /></dt>
  584. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Equivalent to <code class="docutils literal notranslate"><span class="pre">PyErr_GivenExceptionMatches(PyErr_Occurred(),</span> <span class="pre">exc)</span></code>. This
  585. should only be called when an exception is actually set; a memory access
  586. violation will occur if no exception has been raised.</p>
  587. </dd></dl>
  588. <dl class="c function">
  589. <dt class="sig sig-object c" id="c.PyErr_GivenExceptionMatches">
  590. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_GivenExceptionMatches</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">given</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_GivenExceptionMatches" title="Link to this definition">¶</a><br /></dt>
  591. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Return true if the <em>given</em> exception matches the exception type in <em>exc</em>. If
  592. <em>exc</em> is a class object, this also returns true when <em>given</em> is an instance
  593. of a subclass. If <em>exc</em> is a tuple, all exception types in the tuple (and
  594. recursively in subtuples) are searched for a match.</p>
  595. </dd></dl>
  596. <dl class="c function">
  597. <dt class="sig sig-object c" id="c.PyErr_GetRaisedException">
  598. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_GetRaisedException</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_GetRaisedException" title="Link to this definition">¶</a><br /></dt>
  599. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.12.</em><p>Return the exception currently being raised, clearing the error indicator at
  600. the same time. Return <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if the error indicator is not set.</p>
  601. <p>This function is used by code that needs to catch exceptions,
  602. or code that needs to save and restore the error indicator temporarily.</p>
  603. <p>For example:</p>
  604. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
  605. <span class="w"> </span><span class="n">PyObject</span><span class="w"> </span><span class="o">*</span><span class="n">exc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyErr_GetRaisedException</span><span class="p">();</span>
  606. <span class="w"> </span><span class="cm">/* ... code that might produce other errors ... */</span>
  607. <span class="w"> </span><span class="n">PyErr_SetRaisedException</span><span class="p">(</span><span class="n">exc</span><span class="p">);</span>
  608. <span class="p">}</span>
  609. </pre></div>
  610. </div>
  611. <div class="admonition seealso">
  612. <p class="admonition-title">See also</p>
  613. <p><a class="reference internal" href="#c.PyErr_GetHandledException" title="PyErr_GetHandledException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetHandledException()</span></code></a>,
  614. to save the exception currently being handled.</p>
  615. </div>
  616. <div class="versionadded">
  617. <p><span class="versionmodified added">New in version 3.12.</span></p>
  618. </div>
  619. </dd></dl>
  620. <dl class="c function">
  621. <dt class="sig sig-object c" id="c.PyErr_SetRaisedException">
  622. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetRaisedException</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetRaisedException" title="Link to this definition">¶</a><br /></dt>
  623. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.12.</em><p>Set <em>exc</em> as the exception currently being raised,
  624. clearing the existing exception if one is set.</p>
  625. <div class="admonition warning">
  626. <p class="admonition-title">Warning</p>
  627. <p>This call steals a reference to <em>exc</em>, which must be a valid exception.</p>
  628. </div>
  629. <div class="versionadded">
  630. <p><span class="versionmodified added">New in version 3.12.</span></p>
  631. </div>
  632. </dd></dl>
  633. <dl class="c function">
  634. <dt class="sig sig-object c" id="c.PyErr_Fetch">
  635. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_Fetch</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ptype</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">pvalue</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ptraceback</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_Fetch" title="Link to this definition">¶</a><br /></dt>
  636. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><div class="deprecated">
  637. <p><span class="versionmodified deprecated">Deprecated since version 3.12: </span>Use <a class="reference internal" href="#c.PyErr_GetRaisedException" title="PyErr_GetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetRaisedException()</span></code></a> instead.</p>
  638. </div>
  639. <p>Retrieve the error indicator into three variables whose addresses are passed.
  640. If the error indicator is not set, set all three variables to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>. If it is
  641. set, it will be cleared and you own a reference to each object retrieved. The
  642. value and traceback object may be <code class="docutils literal notranslate"><span class="pre">NULL</span></code> even when the type object is not.</p>
  643. <div class="admonition note">
  644. <p class="admonition-title">Note</p>
  645. <p>This function is normally only used by legacy code that needs to catch
  646. exceptions or save and restore the error indicator temporarily.</p>
  647. <p>For example:</p>
  648. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
  649. <span class="w"> </span><span class="n">PyObject</span><span class="w"> </span><span class="o">*</span><span class="n">type</span><span class="p">,</span><span class="w"> </span><span class="o">*</span><span class="n">value</span><span class="p">,</span><span class="w"> </span><span class="o">*</span><span class="n">traceback</span><span class="p">;</span>
  650. <span class="w"> </span><span class="n">PyErr_Fetch</span><span class="p">(</span><span class="o">&amp;</span><span class="n">type</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">value</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">traceback</span><span class="p">);</span>
  651. <span class="w"> </span><span class="cm">/* ... code that might produce other errors ... */</span>
  652. <span class="w"> </span><span class="n">PyErr_Restore</span><span class="p">(</span><span class="n">type</span><span class="p">,</span><span class="w"> </span><span class="n">value</span><span class="p">,</span><span class="w"> </span><span class="n">traceback</span><span class="p">);</span>
  653. <span class="p">}</span>
  654. </pre></div>
  655. </div>
  656. </div>
  657. </dd></dl>
  658. <dl class="c function">
  659. <dt class="sig sig-object c" id="c.PyErr_Restore">
  660. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_Restore</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">value</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">traceback</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_Restore" title="Link to this definition">¶</a><br /></dt>
  661. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><div class="deprecated">
  662. <p><span class="versionmodified deprecated">Deprecated since version 3.12: </span>Use <a class="reference internal" href="#c.PyErr_SetRaisedException" title="PyErr_SetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetRaisedException()</span></code></a> instead.</p>
  663. </div>
  664. <p>Set the error indicator from the three objects,
  665. <em>type</em>, <em>value</em>, and <em>traceback</em>,
  666. clearing the existing exception if one is set.
  667. If the objects are <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, the error
  668. indicator is cleared. Do not pass a <code class="docutils literal notranslate"><span class="pre">NULL</span></code> type and non-<code class="docutils literal notranslate"><span class="pre">NULL</span></code> value or
  669. traceback. The exception type should be a class. Do not pass an invalid
  670. exception type or value. (Violating these rules will cause subtle problems
  671. later.) This call takes away a reference to each object: you must own a
  672. reference to each object before the call and after the call you no longer own
  673. these references. (If you don’t understand this, don’t use this function. I
  674. warned you.)</p>
  675. <div class="admonition note">
  676. <p class="admonition-title">Note</p>
  677. <p>This function is normally only used by legacy code that needs to
  678. save and restore the error indicator temporarily.
  679. Use <a class="reference internal" href="#c.PyErr_Fetch" title="PyErr_Fetch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Fetch()</span></code></a> to save the current error indicator.</p>
  680. </div>
  681. </dd></dl>
  682. <dl class="c function">
  683. <dt class="sig sig-object c" id="c.PyErr_NormalizeException">
  684. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_NormalizeException</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">val</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">tb</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_NormalizeException" title="Link to this definition">¶</a><br /></dt>
  685. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><div class="deprecated">
  686. <p><span class="versionmodified deprecated">Deprecated since version 3.12: </span>Use <a class="reference internal" href="#c.PyErr_GetRaisedException" title="PyErr_GetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetRaisedException()</span></code></a> instead,
  687. to avoid any possible de-normalization.</p>
  688. </div>
  689. <p>Under certain circumstances, the values returned by <a class="reference internal" href="#c.PyErr_Fetch" title="PyErr_Fetch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Fetch()</span></code></a> below
  690. can be “unnormalized”, meaning that <code class="docutils literal notranslate"><span class="pre">*exc</span></code> is a class object but <code class="docutils literal notranslate"><span class="pre">*val</span></code> is
  691. not an instance of the same class. This function can be used to instantiate
  692. the class in that case. If the values are already normalized, nothing happens.
  693. The delayed normalization is implemented to improve performance.</p>
  694. <div class="admonition note">
  695. <p class="admonition-title">Note</p>
  696. <p>This function <em>does not</em> implicitly set the
  697. <a class="reference internal" href="../library/exceptions.html#BaseException.__traceback__" title="BaseException.__traceback__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__traceback__</span></code></a>
  698. attribute on the exception value. If setting the traceback
  699. appropriately is desired, the following additional snippet is needed:</p>
  700. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">tb</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
  701. <span class="w"> </span><span class="n">PyException_SetTraceback</span><span class="p">(</span><span class="n">val</span><span class="p">,</span><span class="w"> </span><span class="n">tb</span><span class="p">);</span>
  702. <span class="p">}</span>
  703. </pre></div>
  704. </div>
  705. </div>
  706. </dd></dl>
  707. <dl class="c function">
  708. <dt class="sig sig-object c" id="c.PyErr_GetHandledException">
  709. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_GetHandledException</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_GetHandledException" title="Link to this definition">¶</a><br /></dt>
  710. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.11.</em><p>Retrieve the active exception instance, as would be returned by <a class="reference internal" href="../library/sys.html#sys.exception" title="sys.exception"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exception()</span></code></a>.
  711. This refers to an exception that was <em>already caught</em>, not to an exception that was
  712. freshly raised. Returns a new reference to the exception or <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.
  713. Does not modify the interpreter’s exception state.</p>
  714. <div class="admonition note">
  715. <p class="admonition-title">Note</p>
  716. <p>This function is not normally used by code that wants to handle exceptions.
  717. Rather, it can be used when code needs to save and restore the exception
  718. state temporarily. Use <a class="reference internal" href="#c.PyErr_SetHandledException" title="PyErr_SetHandledException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetHandledException()</span></code></a> to restore or
  719. clear the exception state.</p>
  720. </div>
  721. <div class="versionadded">
  722. <p><span class="versionmodified added">New in version 3.11.</span></p>
  723. </div>
  724. </dd></dl>
  725. <dl class="c function">
  726. <dt class="sig sig-object c" id="c.PyErr_SetHandledException">
  727. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetHandledException</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetHandledException" title="Link to this definition">¶</a><br /></dt>
  728. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.11.</em><p>Set the active exception, as known from <code class="docutils literal notranslate"><span class="pre">sys.exception()</span></code>. This refers
  729. to an exception that was <em>already caught</em>, not to an exception that was
  730. freshly raised.
  731. To clear the exception state, pass <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  732. <div class="admonition note">
  733. <p class="admonition-title">Note</p>
  734. <p>This function is not normally used by code that wants to handle exceptions.
  735. Rather, it can be used when code needs to save and restore the exception
  736. state temporarily. Use <a class="reference internal" href="#c.PyErr_GetHandledException" title="PyErr_GetHandledException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetHandledException()</span></code></a> to get the exception
  737. state.</p>
  738. </div>
  739. <div class="versionadded">
  740. <p><span class="versionmodified added">New in version 3.11.</span></p>
  741. </div>
  742. </dd></dl>
  743. <dl class="c function">
  744. <dt class="sig sig-object c" id="c.PyErr_GetExcInfo">
  745. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_GetExcInfo</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ptype</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">pvalue</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ptraceback</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_GetExcInfo" title="Link to this definition">¶</a><br /></dt>
  746. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.7.</em><p>Retrieve the old-style representation of the exception info, as known from
  747. <a class="reference internal" href="../library/sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a>. This refers to an exception that was <em>already caught</em>,
  748. not to an exception that was freshly raised. Returns new references for the
  749. three objects, any of which may be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>. Does not modify the exception
  750. info state. This function is kept for backwards compatibility. Prefer using
  751. <a class="reference internal" href="#c.PyErr_GetHandledException" title="PyErr_GetHandledException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetHandledException()</span></code></a>.</p>
  752. <div class="admonition note">
  753. <p class="admonition-title">Note</p>
  754. <p>This function is not normally used by code that wants to handle exceptions.
  755. Rather, it can be used when code needs to save and restore the exception
  756. state temporarily. Use <a class="reference internal" href="#c.PyErr_SetExcInfo" title="PyErr_SetExcInfo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetExcInfo()</span></code></a> to restore or clear the
  757. exception state.</p>
  758. </div>
  759. <div class="versionadded">
  760. <p><span class="versionmodified added">New in version 3.3.</span></p>
  761. </div>
  762. </dd></dl>
  763. <dl class="c function">
  764. <dt class="sig sig-object c" id="c.PyErr_SetExcInfo">
  765. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetExcInfo</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">type</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">value</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">traceback</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetExcInfo" title="Link to this definition">¶</a><br /></dt>
  766. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.7.</em><p>Set the exception info, as known from <code class="docutils literal notranslate"><span class="pre">sys.exc_info()</span></code>. This refers
  767. to an exception that was <em>already caught</em>, not to an exception that was
  768. freshly raised. This function steals the references of the arguments.
  769. To clear the exception state, pass <code class="docutils literal notranslate"><span class="pre">NULL</span></code> for all three arguments.
  770. This function is kept for backwards compatibility. Prefer using
  771. <a class="reference internal" href="#c.PyErr_SetHandledException" title="PyErr_SetHandledException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetHandledException()</span></code></a>.</p>
  772. <div class="admonition note">
  773. <p class="admonition-title">Note</p>
  774. <p>This function is not normally used by code that wants to handle exceptions.
  775. Rather, it can be used when code needs to save and restore the exception
  776. state temporarily. Use <a class="reference internal" href="#c.PyErr_GetExcInfo" title="PyErr_GetExcInfo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetExcInfo()</span></code></a> to read the exception
  777. state.</p>
  778. </div>
  779. <div class="versionadded">
  780. <p><span class="versionmodified added">New in version 3.3.</span></p>
  781. </div>
  782. <div class="versionchanged">
  783. <p><span class="versionmodified changed">Changed in version 3.11: </span>The <code class="docutils literal notranslate"><span class="pre">type</span></code> and <code class="docutils literal notranslate"><span class="pre">traceback</span></code> arguments are no longer used and
  784. can be NULL. The interpreter now derives them from the exception
  785. instance (the <code class="docutils literal notranslate"><span class="pre">value</span></code> argument). The function still steals
  786. references of all three arguments.</p>
  787. </div>
  788. </dd></dl>
  789. </section>
  790. <section id="signal-handling">
  791. <h2>Signal Handling<a class="headerlink" href="#signal-handling" title="Link to this heading">¶</a></h2>
  792. <dl class="c function">
  793. <dt class="sig sig-object c" id="c.PyErr_CheckSignals">
  794. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_CheckSignals</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_CheckSignals" title="Link to this definition">¶</a><br /></dt>
  795. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p id="index-1">This function interacts with Python’s signal handling.</p>
  796. <p>If the function is called from the main thread and under the main Python
  797. interpreter, it checks whether a signal has been sent to the processes
  798. and if so, invokes the corresponding signal handler. If the <a class="reference internal" href="../library/signal.html#module-signal" title="signal: Set handlers for asynchronous events."><code class="xref py py-mod docutils literal notranslate"><span class="pre">signal</span></code></a>
  799. module is supported, this can invoke a signal handler written in Python.</p>
  800. <p>The function attempts to handle all pending signals, and then returns <code class="docutils literal notranslate"><span class="pre">0</span></code>.
  801. However, if a Python signal handler raises an exception, the error
  802. indicator is set and the function returns <code class="docutils literal notranslate"><span class="pre">-1</span></code> immediately (such that
  803. other pending signals may not have been handled yet: they will be on the
  804. next <a class="reference internal" href="#c.PyErr_CheckSignals" title="PyErr_CheckSignals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_CheckSignals()</span></code></a> invocation).</p>
  805. <p>If the function is called from a non-main thread, or under a non-main
  806. Python interpreter, it does nothing and returns <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  807. <p>This function can be called by long-running C code that wants to
  808. be interruptible by user requests (such as by pressing Ctrl-C).</p>
  809. <div class="admonition note">
  810. <p class="admonition-title">Note</p>
  811. <p>The default Python signal handler for <code class="xref c c-macro docutils literal notranslate"><span class="pre">SIGINT</span></code> raises the
  812. <a class="reference internal" href="../library/exceptions.html#KeyboardInterrupt" title="KeyboardInterrupt"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyboardInterrupt</span></code></a> exception.</p>
  813. </div>
  814. </dd></dl>
  815. <dl class="c function">
  816. <dt class="sig sig-object c" id="c.PyErr_SetInterrupt">
  817. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetInterrupt</span></span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetInterrupt" title="Link to this definition">¶</a><br /></dt>
  818. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p id="index-2">Simulate the effect of a <code class="xref c c-macro docutils literal notranslate"><span class="pre">SIGINT</span></code> signal arriving.
  819. This is equivalent to <code class="docutils literal notranslate"><span class="pre">PyErr_SetInterruptEx(SIGINT)</span></code>.</p>
  820. <div class="admonition note">
  821. <p class="admonition-title">Note</p>
  822. <p>This function is async-signal-safe. It can be called without
  823. the <a class="reference internal" href="../glossary.html#term-GIL"><span class="xref std std-term">GIL</span></a> and from a C signal handler.</p>
  824. </div>
  825. </dd></dl>
  826. <dl class="c function">
  827. <dt class="sig sig-object c" id="c.PyErr_SetInterruptEx">
  828. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_SetInterruptEx</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">signum</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_SetInterruptEx" title="Link to this definition">¶</a><br /></dt>
  829. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.10.</em><p id="index-3">Simulate the effect of a signal arriving. The next time
  830. <a class="reference internal" href="#c.PyErr_CheckSignals" title="PyErr_CheckSignals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_CheckSignals()</span></code></a> is called, the Python signal handler for
  831. the given signal number will be called.</p>
  832. <p>This function can be called by C code that sets up its own signal handling
  833. and wants Python signal handlers to be invoked as expected when an
  834. interruption is requested (for example when the user presses Ctrl-C
  835. to interrupt an operation).</p>
  836. <p>If the given signal isn’t handled by Python (it was set to
  837. <a class="reference internal" href="../library/signal.html#signal.SIG_DFL" title="signal.SIG_DFL"><code class="xref py py-const docutils literal notranslate"><span class="pre">signal.SIG_DFL</span></code></a> or <a class="reference internal" href="../library/signal.html#signal.SIG_IGN" title="signal.SIG_IGN"><code class="xref py py-const docutils literal notranslate"><span class="pre">signal.SIG_IGN</span></code></a>), it will be ignored.</p>
  838. <p>If <em>signum</em> is outside of the allowed range of signal numbers, <code class="docutils literal notranslate"><span class="pre">-1</span></code>
  839. is returned. Otherwise, <code class="docutils literal notranslate"><span class="pre">0</span></code> is returned. The error indicator is
  840. never changed by this function.</p>
  841. <div class="admonition note">
  842. <p class="admonition-title">Note</p>
  843. <p>This function is async-signal-safe. It can be called without
  844. the <a class="reference internal" href="../glossary.html#term-GIL"><span class="xref std std-term">GIL</span></a> and from a C signal handler.</p>
  845. </div>
  846. <div class="versionadded">
  847. <p><span class="versionmodified added">New in version 3.10.</span></p>
  848. </div>
  849. </dd></dl>
  850. <dl class="c function">
  851. <dt class="sig sig-object c" id="c.PySignal_SetWakeupFd">
  852. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PySignal_SetWakeupFd</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">fd</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PySignal_SetWakeupFd" title="Link to this definition">¶</a><br /></dt>
  853. <dd><p>This utility function specifies a file descriptor to which the signal number
  854. is written as a single byte whenever a signal is received. <em>fd</em> must be
  855. non-blocking. It returns the previous such file descriptor.</p>
  856. <p>The value <code class="docutils literal notranslate"><span class="pre">-1</span></code> disables the feature; this is the initial state.
  857. This is equivalent to <a class="reference internal" href="../library/signal.html#signal.set_wakeup_fd" title="signal.set_wakeup_fd"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.set_wakeup_fd()</span></code></a> in Python, but without any
  858. error checking. <em>fd</em> should be a valid file descriptor. The function should
  859. only be called from the main thread.</p>
  860. <div class="versionchanged">
  861. <p><span class="versionmodified changed">Changed in version 3.5: </span>On Windows, the function now also supports socket handles.</p>
  862. </div>
  863. </dd></dl>
  864. </section>
  865. <section id="exception-classes">
  866. <h2>Exception Classes<a class="headerlink" href="#exception-classes" title="Link to this heading">¶</a></h2>
  867. <dl class="c function">
  868. <dt class="sig sig-object c" id="c.PyErr_NewException">
  869. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_NewException</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">base</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dict</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_NewException" title="Link to this definition">¶</a><br /></dt>
  870. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>This utility function creates and returns a new exception class. The <em>name</em>
  871. argument must be the name of the new exception, a C string of the form
  872. <code class="docutils literal notranslate"><span class="pre">module.classname</span></code>. The <em>base</em> and <em>dict</em> arguments are normally <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.
  873. This creates a class object derived from <a class="reference internal" href="../library/exceptions.html#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a> (accessible in C as
  874. <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_Exception</span></code>).</p>
  875. <p>The <code class="xref py py-attr docutils literal notranslate"><span class="pre">__module__</span></code> attribute of the new class is set to the first part (up
  876. to the last dot) of the <em>name</em> argument, and the class name is set to the last
  877. part (after the last dot). The <em>base</em> argument can be used to specify alternate
  878. base classes; it can either be only one class or a tuple of classes. The <em>dict</em>
  879. argument can be used to specify a dictionary of class variables and methods.</p>
  880. </dd></dl>
  881. <dl class="c function">
  882. <dt class="sig sig-object c" id="c.PyErr_NewExceptionWithDoc">
  883. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyErr_NewExceptionWithDoc</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">name</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">doc</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">base</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">dict</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyErr_NewExceptionWithDoc" title="Link to this definition">¶</a><br /></dt>
  884. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Same as <a class="reference internal" href="#c.PyErr_NewException" title="PyErr_NewException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_NewException()</span></code></a>, except that the new exception class can
  885. easily be given a docstring: If <em>doc</em> is non-<code class="docutils literal notranslate"><span class="pre">NULL</span></code>, it will be used as the
  886. docstring for the exception class.</p>
  887. <div class="versionadded">
  888. <p><span class="versionmodified added">New in version 3.2.</span></p>
  889. </div>
  890. </dd></dl>
  891. </section>
  892. <section id="exception-objects">
  893. <h2>Exception Objects<a class="headerlink" href="#exception-objects" title="Link to this heading">¶</a></h2>
  894. <dl class="c function">
  895. <dt class="sig sig-object c" id="c.PyException_GetTraceback">
  896. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyException_GetTraceback</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ex</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyException_GetTraceback" title="Link to this definition">¶</a><br /></dt>
  897. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Return the traceback associated with the exception as a new reference, as
  898. accessible from Python through the <a class="reference internal" href="../library/exceptions.html#BaseException.__traceback__" title="BaseException.__traceback__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__traceback__</span></code></a>
  899. attribute. If there is no
  900. traceback associated, this returns <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  901. </dd></dl>
  902. <dl class="c function">
  903. <dt class="sig sig-object c" id="c.PyException_SetTraceback">
  904. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyException_SetTraceback</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ex</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">tb</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyException_SetTraceback" title="Link to this definition">¶</a><br /></dt>
  905. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Set the traceback associated with the exception to <em>tb</em>. Use <code class="docutils literal notranslate"><span class="pre">Py_None</span></code> to
  906. clear it.</p>
  907. </dd></dl>
  908. <dl class="c function">
  909. <dt class="sig sig-object c" id="c.PyException_GetContext">
  910. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyException_GetContext</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ex</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyException_GetContext" title="Link to this definition">¶</a><br /></dt>
  911. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Return the context (another exception instance during whose handling <em>ex</em> was
  912. raised) associated with the exception as a new reference, as accessible from
  913. Python through the <a class="reference internal" href="../library/exceptions.html#BaseException.__context__" title="BaseException.__context__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__context__</span></code></a> attribute.
  914. If there is no context associated, this returns <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  915. </dd></dl>
  916. <dl class="c function">
  917. <dt class="sig sig-object c" id="c.PyException_SetContext">
  918. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyException_SetContext</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ex</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ctx</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyException_SetContext" title="Link to this definition">¶</a><br /></dt>
  919. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Set the context associated with the exception to <em>ctx</em>. Use <code class="docutils literal notranslate"><span class="pre">NULL</span></code> to clear
  920. it. There is no type check to make sure that <em>ctx</em> is an exception instance.
  921. This steals a reference to <em>ctx</em>.</p>
  922. </dd></dl>
  923. <dl class="c function">
  924. <dt class="sig sig-object c" id="c.PyException_GetCause">
  925. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyException_GetCause</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ex</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyException_GetCause" title="Link to this definition">¶</a><br /></dt>
  926. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Return the cause (either an exception instance, or <code class="docutils literal notranslate"><span class="pre">None</span></code>,
  927. set by <code class="docutils literal notranslate"><span class="pre">raise</span> <span class="pre">...</span> <span class="pre">from</span> <span class="pre">...</span></code>) associated with the exception as a new
  928. reference, as accessible from Python through the
  929. <a class="reference internal" href="../library/exceptions.html#BaseException.__cause__" title="BaseException.__cause__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__cause__</span></code></a> attribute.</p>
  930. </dd></dl>
  931. <dl class="c function">
  932. <dt class="sig sig-object c" id="c.PyException_SetCause">
  933. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyException_SetCause</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ex</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">cause</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyException_SetCause" title="Link to this definition">¶</a><br /></dt>
  934. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Set the cause associated with the exception to <em>cause</em>. Use <code class="docutils literal notranslate"><span class="pre">NULL</span></code> to clear
  935. it. There is no type check to make sure that <em>cause</em> is either an exception
  936. instance or <code class="docutils literal notranslate"><span class="pre">None</span></code>. This steals a reference to <em>cause</em>.</p>
  937. <p>The <a class="reference internal" href="../library/exceptions.html#BaseException.__suppress_context__" title="BaseException.__suppress_context__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__suppress_context__</span></code></a> attribute is implicitly set
  938. to <code class="docutils literal notranslate"><span class="pre">True</span></code> by this function.</p>
  939. </dd></dl>
  940. <dl class="c function">
  941. <dt class="sig sig-object c" id="c.PyException_GetArgs">
  942. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyException_GetArgs</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ex</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyException_GetArgs" title="Link to this definition">¶</a><br /></dt>
  943. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.12.</em><p>Return <a class="reference internal" href="../library/exceptions.html#BaseException.args" title="BaseException.args"><code class="xref py py-attr docutils literal notranslate"><span class="pre">args</span></code></a> of exception <em>ex</em>.</p>
  944. </dd></dl>
  945. <dl class="c function">
  946. <dt class="sig sig-object c" id="c.PyException_SetArgs">
  947. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyException_SetArgs</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ex</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyException_SetArgs" title="Link to this definition">¶</a><br /></dt>
  948. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.12.</em><p>Set <a class="reference internal" href="../library/exceptions.html#BaseException.args" title="BaseException.args"><code class="xref py py-attr docutils literal notranslate"><span class="pre">args</span></code></a> of exception <em>ex</em> to <em>args</em>.</p>
  949. </dd></dl>
  950. <dl class="c function">
  951. <dt class="sig sig-object c" id="c.PyUnstable_Exc_PrepReraiseStar">
  952. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyUnstable_Exc_PrepReraiseStar</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">orig</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">excs</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnstable_Exc_PrepReraiseStar" title="Link to this definition">¶</a><br /></dt>
  953. <dd><div class="unstable-c-api warning admonition">
  954. <em>This is <a class="reference internal" href="stable.html#unstable-c-api"><span class="std std-ref">Unstable API</span></a>. It may change without warning in minor releases.</em></div>
  955. <p>Implement part of the interpreter’s implementation of <code class="xref std std-keyword docutils literal notranslate"><span class="pre">except*</span></code>.
  956. <em>orig</em> is the original exception that was caught, and <em>excs</em> is the list of
  957. the exceptions that need to be raised. This list contains the unhandled
  958. part of <em>orig</em>, if any, as well as the exceptions that were raised from the
  959. <code class="xref std std-keyword docutils literal notranslate"><span class="pre">except*</span></code> clauses (so they have a different traceback from <em>orig</em>) and
  960. those that were reraised (and have the same traceback as <em>orig</em>).
  961. Return the <a class="reference internal" href="../library/exceptions.html#ExceptionGroup" title="ExceptionGroup"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExceptionGroup</span></code></a> that needs to be reraised in the end, or
  962. <code class="docutils literal notranslate"><span class="pre">None</span></code> if there is nothing to reraise.</p>
  963. <div class="versionadded">
  964. <p><span class="versionmodified added">New in version 3.12.</span></p>
  965. </div>
  966. </dd></dl>
  967. </section>
  968. <section id="unicode-exception-objects">
  969. <span id="unicodeexceptions"></span><h2>Unicode Exception Objects<a class="headerlink" href="#unicode-exception-objects" title="Link to this heading">¶</a></h2>
  970. <p>The following functions are used to create and modify Unicode exceptions from C.</p>
  971. <dl class="c function">
  972. <dt class="sig sig-object c" id="c.PyUnicodeDecodeError_Create">
  973. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeDecodeError_Create</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">encoding</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">object</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">length</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">end</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">reason</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeDecodeError_Create" title="Link to this definition">¶</a><br /></dt>
  974. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Create a <a class="reference internal" href="../library/exceptions.html#UnicodeDecodeError" title="UnicodeDecodeError"><code class="xref py py-class docutils literal notranslate"><span class="pre">UnicodeDecodeError</span></code></a> object with the attributes <em>encoding</em>,
  975. <em>object</em>, <em>length</em>, <em>start</em>, <em>end</em> and <em>reason</em>. <em>encoding</em> and <em>reason</em> are
  976. UTF-8 encoded strings.</p>
  977. </dd></dl>
  978. <dl class="c function">
  979. <dt class="sig sig-object c" id="c.PyUnicodeDecodeError_GetEncoding">
  980. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeDecodeError_GetEncoding</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeDecodeError_GetEncoding" title="Link to this definition">¶</a><br /></dt>
  981. <dt class="sig sig-object c" id="c.PyUnicodeEncodeError_GetEncoding">
  982. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeEncodeError_GetEncoding</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeEncodeError_GetEncoding" title="Link to this definition">¶</a><br /></dt>
  983. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Return the <em>encoding</em> attribute of the given exception object.</p>
  984. </dd></dl>
  985. <dl class="c function">
  986. <dt class="sig sig-object c" id="c.PyUnicodeDecodeError_GetObject">
  987. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeDecodeError_GetObject</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeDecodeError_GetObject" title="Link to this definition">¶</a><br /></dt>
  988. <dt class="sig sig-object c" id="c.PyUnicodeEncodeError_GetObject">
  989. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeEncodeError_GetObject</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeEncodeError_GetObject" title="Link to this definition">¶</a><br /></dt>
  990. <dt class="sig sig-object c" id="c.PyUnicodeTranslateError_GetObject">
  991. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeTranslateError_GetObject</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeTranslateError_GetObject" title="Link to this definition">¶</a><br /></dt>
  992. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Return the <em>object</em> attribute of the given exception object.</p>
  993. </dd></dl>
  994. <dl class="c function">
  995. <dt class="sig sig-object c" id="c.PyUnicodeDecodeError_GetStart">
  996. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeDecodeError_GetStart</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">start</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeDecodeError_GetStart" title="Link to this definition">¶</a><br /></dt>
  997. <dt class="sig sig-object c" id="c.PyUnicodeEncodeError_GetStart">
  998. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeEncodeError_GetStart</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">start</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeEncodeError_GetStart" title="Link to this definition">¶</a><br /></dt>
  999. <dt class="sig sig-object c" id="c.PyUnicodeTranslateError_GetStart">
  1000. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeTranslateError_GetStart</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">start</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeTranslateError_GetStart" title="Link to this definition">¶</a><br /></dt>
  1001. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Get the <em>start</em> attribute of the given exception object and place it into
  1002. <em>*start</em>. <em>start</em> must not be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>. Return <code class="docutils literal notranslate"><span class="pre">0</span></code> on success, <code class="docutils literal notranslate"><span class="pre">-1</span></code> on
  1003. failure.</p>
  1004. </dd></dl>
  1005. <dl class="c function">
  1006. <dt class="sig sig-object c" id="c.PyUnicodeDecodeError_SetStart">
  1007. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeDecodeError_SetStart</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">start</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeDecodeError_SetStart" title="Link to this definition">¶</a><br /></dt>
  1008. <dt class="sig sig-object c" id="c.PyUnicodeEncodeError_SetStart">
  1009. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeEncodeError_SetStart</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">start</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeEncodeError_SetStart" title="Link to this definition">¶</a><br /></dt>
  1010. <dt class="sig sig-object c" id="c.PyUnicodeTranslateError_SetStart">
  1011. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeTranslateError_SetStart</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">start</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeTranslateError_SetStart" title="Link to this definition">¶</a><br /></dt>
  1012. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Set the <em>start</em> attribute of the given exception object to <em>start</em>. Return
  1013. <code class="docutils literal notranslate"><span class="pre">0</span></code> on success, <code class="docutils literal notranslate"><span class="pre">-1</span></code> on failure.</p>
  1014. </dd></dl>
  1015. <dl class="c function">
  1016. <dt class="sig sig-object c" id="c.PyUnicodeDecodeError_GetEnd">
  1017. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeDecodeError_GetEnd</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">end</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeDecodeError_GetEnd" title="Link to this definition">¶</a><br /></dt>
  1018. <dt class="sig sig-object c" id="c.PyUnicodeEncodeError_GetEnd">
  1019. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeEncodeError_GetEnd</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">end</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeEncodeError_GetEnd" title="Link to this definition">¶</a><br /></dt>
  1020. <dt class="sig sig-object c" id="c.PyUnicodeTranslateError_GetEnd">
  1021. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeTranslateError_GetEnd</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">end</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeTranslateError_GetEnd" title="Link to this definition">¶</a><br /></dt>
  1022. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Get the <em>end</em> attribute of the given exception object and place it into
  1023. <em>*end</em>. <em>end</em> must not be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>. Return <code class="docutils literal notranslate"><span class="pre">0</span></code> on success, <code class="docutils literal notranslate"><span class="pre">-1</span></code> on
  1024. failure.</p>
  1025. </dd></dl>
  1026. <dl class="c function">
  1027. <dt class="sig sig-object c" id="c.PyUnicodeDecodeError_SetEnd">
  1028. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeDecodeError_SetEnd</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">end</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeDecodeError_SetEnd" title="Link to this definition">¶</a><br /></dt>
  1029. <dt class="sig sig-object c" id="c.PyUnicodeEncodeError_SetEnd">
  1030. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeEncodeError_SetEnd</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">end</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeEncodeError_SetEnd" title="Link to this definition">¶</a><br /></dt>
  1031. <dt class="sig sig-object c" id="c.PyUnicodeTranslateError_SetEnd">
  1032. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeTranslateError_SetEnd</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">end</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeTranslateError_SetEnd" title="Link to this definition">¶</a><br /></dt>
  1033. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Set the <em>end</em> attribute of the given exception object to <em>end</em>. Return <code class="docutils literal notranslate"><span class="pre">0</span></code>
  1034. on success, <code class="docutils literal notranslate"><span class="pre">-1</span></code> on failure.</p>
  1035. </dd></dl>
  1036. <dl class="c function">
  1037. <dt class="sig sig-object c" id="c.PyUnicodeDecodeError_GetReason">
  1038. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeDecodeError_GetReason</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeDecodeError_GetReason" title="Link to this definition">¶</a><br /></dt>
  1039. <dt class="sig sig-object c" id="c.PyUnicodeEncodeError_GetReason">
  1040. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeEncodeError_GetReason</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeEncodeError_GetReason" title="Link to this definition">¶</a><br /></dt>
  1041. <dt class="sig sig-object c" id="c.PyUnicodeTranslateError_GetReason">
  1042. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeTranslateError_GetReason</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeTranslateError_GetReason" title="Link to this definition">¶</a><br /></dt>
  1043. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Return the <em>reason</em> attribute of the given exception object.</p>
  1044. </dd></dl>
  1045. <dl class="c function">
  1046. <dt class="sig sig-object c" id="c.PyUnicodeDecodeError_SetReason">
  1047. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeDecodeError_SetReason</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">reason</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeDecodeError_SetReason" title="Link to this definition">¶</a><br /></dt>
  1048. <dt class="sig sig-object c" id="c.PyUnicodeEncodeError_SetReason">
  1049. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeEncodeError_SetReason</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">reason</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeEncodeError_SetReason" title="Link to this definition">¶</a><br /></dt>
  1050. <dt class="sig sig-object c" id="c.PyUnicodeTranslateError_SetReason">
  1051. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyUnicodeTranslateError_SetReason</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">exc</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">reason</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyUnicodeTranslateError_SetReason" title="Link to this definition">¶</a><br /></dt>
  1052. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Set the <em>reason</em> attribute of the given exception object to <em>reason</em>. Return
  1053. <code class="docutils literal notranslate"><span class="pre">0</span></code> on success, <code class="docutils literal notranslate"><span class="pre">-1</span></code> on failure.</p>
  1054. </dd></dl>
  1055. </section>
  1056. <section id="recursion-control">
  1057. <span id="recursion"></span><h2>Recursion Control<a class="headerlink" href="#recursion-control" title="Link to this heading">¶</a></h2>
  1058. <p>These two functions provide a way to perform safe recursive calls at the C
  1059. level, both in the core and in extension modules. They are needed if the
  1060. recursive code does not necessarily invoke Python code (which tracks its
  1061. recursion depth automatically).
  1062. They are also not needed for <em>tp_call</em> implementations
  1063. because the <a class="reference internal" href="call.html#call"><span class="std std-ref">call protocol</span></a> takes care of recursion handling.</p>
  1064. <dl class="c function">
  1065. <dt class="sig sig-object c" id="c.Py_EnterRecursiveCall">
  1066. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_EnterRecursiveCall</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">where</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_EnterRecursiveCall" title="Link to this definition">¶</a><br /></dt>
  1067. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.9.</em><p>Marks a point where a recursive C-level call is about to be performed.</p>
  1068. <p>If <code class="xref c c-macro docutils literal notranslate"><span class="pre">USE_STACKCHECK</span></code> is defined, this function checks if the OS
  1069. stack overflowed using <a class="reference internal" href="sys.html#c.PyOS_CheckStack" title="PyOS_CheckStack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_CheckStack()</span></code></a>. If this is the case, it
  1070. sets a <a class="reference internal" href="../library/exceptions.html#MemoryError" title="MemoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">MemoryError</span></code></a> and returns a nonzero value.</p>
  1071. <p>The function then checks if the recursion limit is reached. If this is the
  1072. case, a <a class="reference internal" href="../library/exceptions.html#RecursionError" title="RecursionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RecursionError</span></code></a> is set and a nonzero value is returned.
  1073. Otherwise, zero is returned.</p>
  1074. <p><em>where</em> should be a UTF-8 encoded string such as <code class="docutils literal notranslate"><span class="pre">&quot;</span> <span class="pre">in</span> <span class="pre">instance</span> <span class="pre">check&quot;</span></code> to
  1075. be concatenated to the <a class="reference internal" href="../library/exceptions.html#RecursionError" title="RecursionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RecursionError</span></code></a> message caused by the recursion
  1076. depth limit.</p>
  1077. <div class="versionchanged">
  1078. <p><span class="versionmodified changed">Changed in version 3.9: </span>This function is now also available in the <a class="reference internal" href="stable.html#limited-c-api"><span class="std std-ref">limited API</span></a>.</p>
  1079. </div>
  1080. </dd></dl>
  1081. <dl class="c function">
  1082. <dt class="sig sig-object c" id="c.Py_LeaveRecursiveCall">
  1083. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_LeaveRecursiveCall</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_LeaveRecursiveCall" title="Link to this definition">¶</a><br /></dt>
  1084. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.9.</em><p>Ends a <a class="reference internal" href="#c.Py_EnterRecursiveCall" title="Py_EnterRecursiveCall"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_EnterRecursiveCall()</span></code></a>. Must be called once for each
  1085. <em>successful</em> invocation of <a class="reference internal" href="#c.Py_EnterRecursiveCall" title="Py_EnterRecursiveCall"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_EnterRecursiveCall()</span></code></a>.</p>
  1086. <div class="versionchanged">
  1087. <p><span class="versionmodified changed">Changed in version 3.9: </span>This function is now also available in the <a class="reference internal" href="stable.html#limited-c-api"><span class="std std-ref">limited API</span></a>.</p>
  1088. </div>
  1089. </dd></dl>
  1090. <p>Properly implementing <a class="reference internal" href="typeobj.html#c.PyTypeObject.tp_repr" title="PyTypeObject.tp_repr"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_repr</span></code></a> for container types requires
  1091. special recursion handling. In addition to protecting the stack,
  1092. <a class="reference internal" href="typeobj.html#c.PyTypeObject.tp_repr" title="PyTypeObject.tp_repr"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_repr</span></code></a> also needs to track objects to prevent cycles. The
  1093. following two functions facilitate this functionality. Effectively,
  1094. these are the C equivalent to <a class="reference internal" href="../library/reprlib.html#reprlib.recursive_repr" title="reprlib.recursive_repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">reprlib.recursive_repr()</span></code></a>.</p>
  1095. <dl class="c function">
  1096. <dt class="sig sig-object c" id="c.Py_ReprEnter">
  1097. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_ReprEnter</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">object</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_ReprEnter" title="Link to this definition">¶</a><br /></dt>
  1098. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Called at the beginning of the <a class="reference internal" href="typeobj.html#c.PyTypeObject.tp_repr" title="PyTypeObject.tp_repr"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_repr</span></code></a> implementation to
  1099. detect cycles.</p>
  1100. <p>If the object has already been processed, the function returns a
  1101. positive integer. In that case the <a class="reference internal" href="typeobj.html#c.PyTypeObject.tp_repr" title="PyTypeObject.tp_repr"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_repr</span></code></a> implementation
  1102. should return a string object indicating a cycle. As examples,
  1103. <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> objects return <code class="docutils literal notranslate"><span class="pre">{...}</span></code> and <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> objects
  1104. return <code class="docutils literal notranslate"><span class="pre">[...]</span></code>.</p>
  1105. <p>The function will return a negative integer if the recursion limit
  1106. is reached. In that case the <a class="reference internal" href="typeobj.html#c.PyTypeObject.tp_repr" title="PyTypeObject.tp_repr"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_repr</span></code></a> implementation should
  1107. typically return <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  1108. <p>Otherwise, the function returns zero and the <a class="reference internal" href="typeobj.html#c.PyTypeObject.tp_repr" title="PyTypeObject.tp_repr"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_repr</span></code></a>
  1109. implementation can continue normally.</p>
  1110. </dd></dl>
  1111. <dl class="c function">
  1112. <dt class="sig sig-object c" id="c.Py_ReprLeave">
  1113. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_ReprLeave</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">object</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_ReprLeave" title="Link to this definition">¶</a><br /></dt>
  1114. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Ends a <a class="reference internal" href="#c.Py_ReprEnter" title="Py_ReprEnter"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_ReprEnter()</span></code></a>. Must be called once for each
  1115. invocation of <a class="reference internal" href="#c.Py_ReprEnter" title="Py_ReprEnter"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_ReprEnter()</span></code></a> that returns zero.</p>
  1116. </dd></dl>
  1117. </section>
  1118. <section id="standard-exceptions">
  1119. <span id="standardexceptions"></span><h2>Standard Exceptions<a class="headerlink" href="#standard-exceptions" title="Link to this heading">¶</a></h2>
  1120. <p>All standard Python exceptions are available as global variables whose names are
  1121. <code class="docutils literal notranslate"><span class="pre">PyExc_</span></code> followed by the Python exception name. These have the type
  1122. <span class="c-expr sig sig-inline c"><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n">PyObject</span></a><span class="p">*</span></span>; they are all class objects. For completeness, here are all
  1123. the variables:</p>
  1124. <table class="docutils align-default" id="index-4">
  1125. <thead>
  1126. <tr class="row-odd"><th class="head"><p>C Name</p></th>
  1127. <th class="head"><p>Python Name</p></th>
  1128. <th class="head"><p>Notes</p></th>
  1129. </tr>
  1130. </thead>
  1131. <tbody>
  1132. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_BaseException</span></code></p></td>
  1133. <td><p><a class="reference internal" href="../library/exceptions.html#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a></p></td>
  1134. <td><p><a class="footnote-reference brackets" href="#id7" id="id1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p></td>
  1135. </tr>
  1136. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_Exception</span></code></p></td>
  1137. <td><p><a class="reference internal" href="../library/exceptions.html#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a></p></td>
  1138. <td><p><a class="footnote-reference brackets" href="#id7" id="id2" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p></td>
  1139. </tr>
  1140. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ArithmeticError</span></code></p></td>
  1141. <td><p><a class="reference internal" href="../library/exceptions.html#ArithmeticError" title="ArithmeticError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ArithmeticError</span></code></a></p></td>
  1142. <td><p><a class="footnote-reference brackets" href="#id7" id="id3" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p></td>
  1143. </tr>
  1144. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_AssertionError</span></code></p></td>
  1145. <td><p><a class="reference internal" href="../library/exceptions.html#AssertionError" title="AssertionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AssertionError</span></code></a></p></td>
  1146. <td></td>
  1147. </tr>
  1148. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_AttributeError</span></code></p></td>
  1149. <td><p><a class="reference internal" href="../library/exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a></p></td>
  1150. <td></td>
  1151. </tr>
  1152. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_BlockingIOError</span></code></p></td>
  1153. <td><p><a class="reference internal" href="../library/exceptions.html#BlockingIOError" title="BlockingIOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BlockingIOError</span></code></a></p></td>
  1154. <td></td>
  1155. </tr>
  1156. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_BrokenPipeError</span></code></p></td>
  1157. <td><p><a class="reference internal" href="../library/exceptions.html#BrokenPipeError" title="BrokenPipeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BrokenPipeError</span></code></a></p></td>
  1158. <td></td>
  1159. </tr>
  1160. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_BufferError</span></code></p></td>
  1161. <td><p><a class="reference internal" href="../library/exceptions.html#BufferError" title="BufferError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BufferError</span></code></a></p></td>
  1162. <td></td>
  1163. </tr>
  1164. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ChildProcessError</span></code></p></td>
  1165. <td><p><a class="reference internal" href="../library/exceptions.html#ChildProcessError" title="ChildProcessError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ChildProcessError</span></code></a></p></td>
  1166. <td></td>
  1167. </tr>
  1168. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ConnectionAbortedError</span></code></p></td>
  1169. <td><p><a class="reference internal" href="../library/exceptions.html#ConnectionAbortedError" title="ConnectionAbortedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionAbortedError</span></code></a></p></td>
  1170. <td></td>
  1171. </tr>
  1172. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ConnectionError</span></code></p></td>
  1173. <td><p><a class="reference internal" href="../library/exceptions.html#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a></p></td>
  1174. <td></td>
  1175. </tr>
  1176. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ConnectionRefusedError</span></code></p></td>
  1177. <td><p><a class="reference internal" href="../library/exceptions.html#ConnectionRefusedError" title="ConnectionRefusedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionRefusedError</span></code></a></p></td>
  1178. <td></td>
  1179. </tr>
  1180. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ConnectionResetError</span></code></p></td>
  1181. <td><p><a class="reference internal" href="../library/exceptions.html#ConnectionResetError" title="ConnectionResetError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionResetError</span></code></a></p></td>
  1182. <td></td>
  1183. </tr>
  1184. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_EOFError</span></code></p></td>
  1185. <td><p><a class="reference internal" href="../library/exceptions.html#EOFError" title="EOFError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">EOFError</span></code></a></p></td>
  1186. <td></td>
  1187. </tr>
  1188. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_FileExistsError</span></code></p></td>
  1189. <td><p><a class="reference internal" href="../library/exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a></p></td>
  1190. <td></td>
  1191. </tr>
  1192. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_FileNotFoundError</span></code></p></td>
  1193. <td><p><a class="reference internal" href="../library/exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a></p></td>
  1194. <td></td>
  1195. </tr>
  1196. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_FloatingPointError</span></code></p></td>
  1197. <td><p><a class="reference internal" href="../library/exceptions.html#FloatingPointError" title="FloatingPointError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FloatingPointError</span></code></a></p></td>
  1198. <td></td>
  1199. </tr>
  1200. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_GeneratorExit</span></code></p></td>
  1201. <td><p><a class="reference internal" href="../library/exceptions.html#GeneratorExit" title="GeneratorExit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">GeneratorExit</span></code></a></p></td>
  1202. <td></td>
  1203. </tr>
  1204. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ImportError</span></code></p></td>
  1205. <td><p><a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a></p></td>
  1206. <td></td>
  1207. </tr>
  1208. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_IndentationError</span></code></p></td>
  1209. <td><p><a class="reference internal" href="../library/exceptions.html#IndentationError" title="IndentationError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndentationError</span></code></a></p></td>
  1210. <td></td>
  1211. </tr>
  1212. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_IndexError</span></code></p></td>
  1213. <td><p><a class="reference internal" href="../library/exceptions.html#IndexError" title="IndexError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndexError</span></code></a></p></td>
  1214. <td></td>
  1215. </tr>
  1216. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_InterruptedError</span></code></p></td>
  1217. <td><p><a class="reference internal" href="../library/exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a></p></td>
  1218. <td></td>
  1219. </tr>
  1220. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_IsADirectoryError</span></code></p></td>
  1221. <td><p><a class="reference internal" href="../library/exceptions.html#IsADirectoryError" title="IsADirectoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IsADirectoryError</span></code></a></p></td>
  1222. <td></td>
  1223. </tr>
  1224. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_KeyError</span></code></p></td>
  1225. <td><p><a class="reference internal" href="../library/exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a></p></td>
  1226. <td></td>
  1227. </tr>
  1228. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_KeyboardInterrupt</span></code></p></td>
  1229. <td><p><a class="reference internal" href="../library/exceptions.html#KeyboardInterrupt" title="KeyboardInterrupt"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyboardInterrupt</span></code></a></p></td>
  1230. <td></td>
  1231. </tr>
  1232. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_LookupError</span></code></p></td>
  1233. <td><p><a class="reference internal" href="../library/exceptions.html#LookupError" title="LookupError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">LookupError</span></code></a></p></td>
  1234. <td><p><a class="footnote-reference brackets" href="#id7" id="id4" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p></td>
  1235. </tr>
  1236. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_MemoryError</span></code></p></td>
  1237. <td><p><a class="reference internal" href="../library/exceptions.html#MemoryError" title="MemoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">MemoryError</span></code></a></p></td>
  1238. <td></td>
  1239. </tr>
  1240. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ModuleNotFoundError</span></code></p></td>
  1241. <td><p><a class="reference internal" href="../library/exceptions.html#ModuleNotFoundError" title="ModuleNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ModuleNotFoundError</span></code></a></p></td>
  1242. <td></td>
  1243. </tr>
  1244. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_NameError</span></code></p></td>
  1245. <td><p><a class="reference internal" href="../library/exceptions.html#NameError" title="NameError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NameError</span></code></a></p></td>
  1246. <td></td>
  1247. </tr>
  1248. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_NotADirectoryError</span></code></p></td>
  1249. <td><p><a class="reference internal" href="../library/exceptions.html#NotADirectoryError" title="NotADirectoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotADirectoryError</span></code></a></p></td>
  1250. <td></td>
  1251. </tr>
  1252. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_NotImplementedError</span></code></p></td>
  1253. <td><p><a class="reference internal" href="../library/exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a></p></td>
  1254. <td></td>
  1255. </tr>
  1256. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_OSError</span></code></p></td>
  1257. <td><p><a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a></p></td>
  1258. <td><p><a class="footnote-reference brackets" href="#id7" id="id5" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p></td>
  1259. </tr>
  1260. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_OverflowError</span></code></p></td>
  1261. <td><p><a class="reference internal" href="../library/exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a></p></td>
  1262. <td></td>
  1263. </tr>
  1264. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_PermissionError</span></code></p></td>
  1265. <td><p><a class="reference internal" href="../library/exceptions.html#PermissionError" title="PermissionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PermissionError</span></code></a></p></td>
  1266. <td></td>
  1267. </tr>
  1268. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ProcessLookupError</span></code></p></td>
  1269. <td><p><a class="reference internal" href="../library/exceptions.html#ProcessLookupError" title="ProcessLookupError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ProcessLookupError</span></code></a></p></td>
  1270. <td></td>
  1271. </tr>
  1272. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_RecursionError</span></code></p></td>
  1273. <td><p><a class="reference internal" href="../library/exceptions.html#RecursionError" title="RecursionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RecursionError</span></code></a></p></td>
  1274. <td></td>
  1275. </tr>
  1276. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ReferenceError</span></code></p></td>
  1277. <td><p><a class="reference internal" href="../library/exceptions.html#ReferenceError" title="ReferenceError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ReferenceError</span></code></a></p></td>
  1278. <td></td>
  1279. </tr>
  1280. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_RuntimeError</span></code></p></td>
  1281. <td><p><a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a></p></td>
  1282. <td></td>
  1283. </tr>
  1284. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_StopAsyncIteration</span></code></p></td>
  1285. <td><p><a class="reference internal" href="../library/exceptions.html#StopAsyncIteration" title="StopAsyncIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopAsyncIteration</span></code></a></p></td>
  1286. <td></td>
  1287. </tr>
  1288. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_StopIteration</span></code></p></td>
  1289. <td><p><a class="reference internal" href="../library/exceptions.html#StopIteration" title="StopIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code></a></p></td>
  1290. <td></td>
  1291. </tr>
  1292. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_SyntaxError</span></code></p></td>
  1293. <td><p><a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a></p></td>
  1294. <td></td>
  1295. </tr>
  1296. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_SystemError</span></code></p></td>
  1297. <td><p><a class="reference internal" href="../library/exceptions.html#SystemError" title="SystemError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemError</span></code></a></p></td>
  1298. <td></td>
  1299. </tr>
  1300. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_SystemExit</span></code></p></td>
  1301. <td><p><a class="reference internal" href="../library/exceptions.html#SystemExit" title="SystemExit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemExit</span></code></a></p></td>
  1302. <td></td>
  1303. </tr>
  1304. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_TabError</span></code></p></td>
  1305. <td><p><a class="reference internal" href="../library/exceptions.html#TabError" title="TabError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TabError</span></code></a></p></td>
  1306. <td></td>
  1307. </tr>
  1308. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_TimeoutError</span></code></p></td>
  1309. <td><p><a class="reference internal" href="../library/exceptions.html#TimeoutError" title="TimeoutError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TimeoutError</span></code></a></p></td>
  1310. <td></td>
  1311. </tr>
  1312. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_TypeError</span></code></p></td>
  1313. <td><p><a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a></p></td>
  1314. <td></td>
  1315. </tr>
  1316. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_UnboundLocalError</span></code></p></td>
  1317. <td><p><a class="reference internal" href="../library/exceptions.html#UnboundLocalError" title="UnboundLocalError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnboundLocalError</span></code></a></p></td>
  1318. <td></td>
  1319. </tr>
  1320. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_UnicodeDecodeError</span></code></p></td>
  1321. <td><p><a class="reference internal" href="../library/exceptions.html#UnicodeDecodeError" title="UnicodeDecodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeDecodeError</span></code></a></p></td>
  1322. <td></td>
  1323. </tr>
  1324. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_UnicodeEncodeError</span></code></p></td>
  1325. <td><p><a class="reference internal" href="../library/exceptions.html#UnicodeEncodeError" title="UnicodeEncodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeEncodeError</span></code></a></p></td>
  1326. <td></td>
  1327. </tr>
  1328. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_UnicodeError</span></code></p></td>
  1329. <td><p><a class="reference internal" href="../library/exceptions.html#UnicodeError" title="UnicodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeError</span></code></a></p></td>
  1330. <td></td>
  1331. </tr>
  1332. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_UnicodeTranslateError</span></code></p></td>
  1333. <td><p><a class="reference internal" href="../library/exceptions.html#UnicodeTranslateError" title="UnicodeTranslateError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeTranslateError</span></code></a></p></td>
  1334. <td></td>
  1335. </tr>
  1336. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ValueError</span></code></p></td>
  1337. <td><p><a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a></p></td>
  1338. <td></td>
  1339. </tr>
  1340. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ZeroDivisionError</span></code></p></td>
  1341. <td><p><a class="reference internal" href="../library/exceptions.html#ZeroDivisionError" title="ZeroDivisionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ZeroDivisionError</span></code></a></p></td>
  1342. <td></td>
  1343. </tr>
  1344. </tbody>
  1345. </table>
  1346. <div class="versionadded">
  1347. <p><span class="versionmodified added">New in version 3.3: </span><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_BlockingIOError</span></code>, <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_BrokenPipeError</span></code>,
  1348. <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ChildProcessError</span></code>, <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ConnectionError</span></code>,
  1349. <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ConnectionAbortedError</span></code>, <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ConnectionRefusedError</span></code>,
  1350. <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ConnectionResetError</span></code>, <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_FileExistsError</span></code>,
  1351. <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_FileNotFoundError</span></code>, <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_InterruptedError</span></code>,
  1352. <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_IsADirectoryError</span></code>, <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_NotADirectoryError</span></code>,
  1353. <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_PermissionError</span></code>, <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ProcessLookupError</span></code>
  1354. and <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_TimeoutError</span></code> were introduced following <span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-3151/"><strong>PEP 3151</strong></a>.</p>
  1355. </div>
  1356. <div class="versionadded">
  1357. <p><span class="versionmodified added">New in version 3.5: </span><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_StopAsyncIteration</span></code> and <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_RecursionError</span></code>.</p>
  1358. </div>
  1359. <div class="versionadded">
  1360. <p><span class="versionmodified added">New in version 3.6: </span><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ModuleNotFoundError</span></code>.</p>
  1361. </div>
  1362. <p>These are compatibility aliases to <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_OSError</span></code>:</p>
  1363. <table class="docutils align-default" id="index-6">
  1364. <thead>
  1365. <tr class="row-odd"><th class="head"><p>C Name</p></th>
  1366. <th class="head"><p>Notes</p></th>
  1367. </tr>
  1368. </thead>
  1369. <tbody>
  1370. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_EnvironmentError</span></code></p></td>
  1371. <td></td>
  1372. </tr>
  1373. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_IOError</span></code></p></td>
  1374. <td></td>
  1375. </tr>
  1376. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_WindowsError</span></code></p></td>
  1377. <td><p><a class="footnote-reference brackets" href="#id8" id="id6" role="doc-noteref"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></a></p></td>
  1378. </tr>
  1379. </tbody>
  1380. </table>
  1381. <div class="versionchanged">
  1382. <p><span class="versionmodified changed">Changed in version 3.3: </span>These aliases used to be separate exception types.</p>
  1383. </div>
  1384. <p>Notes:</p>
  1385. <aside class="footnote-list brackets">
  1386. <aside class="footnote brackets" id="id7" role="doc-footnote">
  1387. <span class="label"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></span>
  1388. <span class="backrefs">(<a role="doc-backlink" href="#id1">1</a>,<a role="doc-backlink" href="#id2">2</a>,<a role="doc-backlink" href="#id3">3</a>,<a role="doc-backlink" href="#id4">4</a>,<a role="doc-backlink" href="#id5">5</a>)</span>
  1389. <p>This is a base class for other standard exceptions.</p>
  1390. </aside>
  1391. <aside class="footnote brackets" id="id8" role="doc-footnote">
  1392. <span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id6">2</a><span class="fn-bracket">]</span></span>
  1393. <p>Only defined on Windows; protect code that uses this by testing that the
  1394. preprocessor macro <code class="docutils literal notranslate"><span class="pre">MS_WINDOWS</span></code> is defined.</p>
  1395. </aside>
  1396. </aside>
  1397. </section>
  1398. <section id="standard-warning-categories">
  1399. <span id="standardwarningcategories"></span><h2>Standard Warning Categories<a class="headerlink" href="#standard-warning-categories" title="Link to this heading">¶</a></h2>
  1400. <p>All standard Python warning categories are available as global variables whose
  1401. names are <code class="docutils literal notranslate"><span class="pre">PyExc_</span></code> followed by the Python exception name. These have the type
  1402. <span class="c-expr sig sig-inline c"><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n">PyObject</span></a><span class="p">*</span></span>; they are all class objects. For completeness, here are all
  1403. the variables:</p>
  1404. <table class="docutils align-default" id="index-7">
  1405. <thead>
  1406. <tr class="row-odd"><th class="head"><p>C Name</p></th>
  1407. <th class="head"><p>Python Name</p></th>
  1408. <th class="head"><p>Notes</p></th>
  1409. </tr>
  1410. </thead>
  1411. <tbody>
  1412. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_Warning</span></code></p></td>
  1413. <td><p><a class="reference internal" href="../library/exceptions.html#Warning" title="Warning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Warning</span></code></a></p></td>
  1414. <td><p><a class="footnote-reference brackets" href="#id10" id="id9" role="doc-noteref"><span class="fn-bracket">[</span>3<span class="fn-bracket">]</span></a></p></td>
  1415. </tr>
  1416. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_BytesWarning</span></code></p></td>
  1417. <td><p><a class="reference internal" href="../library/exceptions.html#BytesWarning" title="BytesWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BytesWarning</span></code></a></p></td>
  1418. <td></td>
  1419. </tr>
  1420. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_DeprecationWarning</span></code></p></td>
  1421. <td><p><a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a></p></td>
  1422. <td></td>
  1423. </tr>
  1424. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_FutureWarning</span></code></p></td>
  1425. <td><p><a class="reference internal" href="../library/exceptions.html#FutureWarning" title="FutureWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FutureWarning</span></code></a></p></td>
  1426. <td></td>
  1427. </tr>
  1428. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ImportWarning</span></code></p></td>
  1429. <td><p><a class="reference internal" href="../library/exceptions.html#ImportWarning" title="ImportWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportWarning</span></code></a></p></td>
  1430. <td></td>
  1431. </tr>
  1432. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_PendingDeprecationWarning</span></code></p></td>
  1433. <td><p><a class="reference internal" href="../library/exceptions.html#PendingDeprecationWarning" title="PendingDeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PendingDeprecationWarning</span></code></a></p></td>
  1434. <td></td>
  1435. </tr>
  1436. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ResourceWarning</span></code></p></td>
  1437. <td><p><a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a></p></td>
  1438. <td></td>
  1439. </tr>
  1440. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_RuntimeWarning</span></code></p></td>
  1441. <td><p><a class="reference internal" href="../library/exceptions.html#RuntimeWarning" title="RuntimeWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeWarning</span></code></a></p></td>
  1442. <td></td>
  1443. </tr>
  1444. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_SyntaxWarning</span></code></p></td>
  1445. <td><p><a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a></p></td>
  1446. <td></td>
  1447. </tr>
  1448. <tr class="row-odd"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_UnicodeWarning</span></code></p></td>
  1449. <td><p><a class="reference internal" href="../library/exceptions.html#UnicodeWarning" title="UnicodeWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeWarning</span></code></a></p></td>
  1450. <td></td>
  1451. </tr>
  1452. <tr class="row-even"><td><p><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_UserWarning</span></code></p></td>
  1453. <td><p><a class="reference internal" href="../library/exceptions.html#UserWarning" title="UserWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UserWarning</span></code></a></p></td>
  1454. <td></td>
  1455. </tr>
  1456. </tbody>
  1457. </table>
  1458. <div class="versionadded">
  1459. <p><span class="versionmodified added">New in version 3.2: </span><code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_ResourceWarning</span></code>.</p>
  1460. </div>
  1461. <p>Notes:</p>
  1462. <aside class="footnote-list brackets">
  1463. <aside class="footnote brackets" id="id10" role="doc-footnote">
  1464. <span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id9">3</a><span class="fn-bracket">]</span></span>
  1465. <p>This is a base class for other standard warning categories.</p>
  1466. </aside>
  1467. </aside>
  1468. </section>
  1469. </section>
  1470. <div class="clearer"></div>
  1471. </div>
  1472. </div>
  1473. </div>
  1474. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  1475. <div class="sphinxsidebarwrapper">
  1476. <div>
  1477. <h3><a href="../contents.html">Table of Contents</a></h3>
  1478. <ul>
  1479. <li><a class="reference internal" href="#">Exception Handling</a><ul>
  1480. <li><a class="reference internal" href="#printing-and-clearing">Printing and clearing</a></li>
  1481. <li><a class="reference internal" href="#raising-exceptions">Raising exceptions</a></li>
  1482. <li><a class="reference internal" href="#issuing-warnings">Issuing warnings</a></li>
  1483. <li><a class="reference internal" href="#querying-the-error-indicator">Querying the error indicator</a></li>
  1484. <li><a class="reference internal" href="#signal-handling">Signal Handling</a></li>
  1485. <li><a class="reference internal" href="#exception-classes">Exception Classes</a></li>
  1486. <li><a class="reference internal" href="#exception-objects">Exception Objects</a></li>
  1487. <li><a class="reference internal" href="#unicode-exception-objects">Unicode Exception Objects</a></li>
  1488. <li><a class="reference internal" href="#recursion-control">Recursion Control</a></li>
  1489. <li><a class="reference internal" href="#standard-exceptions">Standard Exceptions</a></li>
  1490. <li><a class="reference internal" href="#standard-warning-categories">Standard Warning Categories</a></li>
  1491. </ul>
  1492. </li>
  1493. </ul>
  1494. </div>
  1495. <div>
  1496. <h4>Previous topic</h4>
  1497. <p class="topless"><a href="refcounting.html"
  1498. title="previous chapter">Reference Counting</a></p>
  1499. </div>
  1500. <div>
  1501. <h4>Next topic</h4>
  1502. <p class="topless"><a href="utilities.html"
  1503. title="next chapter">Utilities</a></p>
  1504. </div>
  1505. <div role="note" aria-label="source link">
  1506. <h3>This Page</h3>
  1507. <ul class="this-page-menu">
  1508. <li><a href="../bugs.html">Report a Bug</a></li>
  1509. <li>
  1510. <a href="https://github.com/python/cpython/blob/main/Doc/c-api/exceptions.rst"
  1511. rel="nofollow">Show Source
  1512. </a>
  1513. </li>
  1514. </ul>
  1515. </div>
  1516. </div>
  1517. <div id="sidebarbutton" title="Collapse sidebar">
  1518. <span>«</span>
  1519. </div>
  1520. </div>
  1521. <div class="clearer"></div>
  1522. </div>
  1523. <div class="related" role="navigation" aria-label="related navigation">
  1524. <h3>Navigation</h3>
  1525. <ul>
  1526. <li class="right" style="margin-right: 10px">
  1527. <a href="../genindex.html" title="General Index"
  1528. >index</a></li>
  1529. <li class="right" >
  1530. <a href="../py-modindex.html" title="Python Module Index"
  1531. >modules</a> |</li>
  1532. <li class="right" >
  1533. <a href="utilities.html" title="Utilities"
  1534. >next</a> |</li>
  1535. <li class="right" >
  1536. <a href="refcounting.html" title="Reference Counting"
  1537. >previous</a> |</li>
  1538. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  1539. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  1540. <li class="switchers">
  1541. <div class="language_switcher_placeholder"></div>
  1542. <div class="version_switcher_placeholder"></div>
  1543. </li>
  1544. <li>
  1545. </li>
  1546. <li id="cpython-language-and-version">
  1547. <a href="../index.html">3.12.3 Documentation</a> &#187;
  1548. </li>
  1549. <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &#187;</li>
  1550. <li class="nav-item nav-item-this"><a href="">Exception Handling</a></li>
  1551. <li class="right">
  1552. <div class="inline-search" role="search">
  1553. <form class="inline-search" action="../search.html" method="get">
  1554. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  1555. <input type="submit" value="Go" />
  1556. </form>
  1557. </div>
  1558. |
  1559. </li>
  1560. <li class="right">
  1561. <label class="theme-selector-label">
  1562. Theme
  1563. <select class="theme-selector" oninput="activateTheme(this.value)">
  1564. <option value="auto" selected>Auto</option>
  1565. <option value="light">Light</option>
  1566. <option value="dark">Dark</option>
  1567. </select>
  1568. </label> |</li>
  1569. </ul>
  1570. </div>
  1571. <div class="footer">
  1572. &copy;
  1573. <a href="../copyright.html">
  1574. Copyright
  1575. </a>
  1576. 2001-2024, Python Software Foundation.
  1577. <br />
  1578. This page is licensed under the Python Software Foundation License Version 2.
  1579. <br />
  1580. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  1581. <br />
  1582. See <a href="/license.html">History and License</a> for more information.<br />
  1583. <br />
  1584. The Python Software Foundation is a non-profit corporation.
  1585. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  1586. <br />
  1587. <br />
  1588. Last updated on Apr 09, 2024 (13:47 UTC).
  1589. <a href="/bugs.html">Found a bug</a>?
  1590. <br />
  1591. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  1592. </div>
  1593. </body>
  1594. </html>
上海开阖软件有限公司 沪ICP备12045867号-1