[ SEA-GHOST MINI SHELL]

Path : /proc/2/task/2/root/usr/share/doc/python-docs-2.7.5/html/c-api/
FILE UPLOADER :
Current File : //proc/2/task/2/root/usr/share/doc/python-docs-2.7.5/html/c-api/exceptions.html


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Exception Handling &mdash; Python 2.7.5 documentation</title>
    
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.7.5',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 2.7.5 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python 2.7.5 documentation" href="../index.html" />
    <link rel="up" title="Python/C API Reference Manual" href="index.html" />
    <link rel="next" title="Utilities" href="utilities.html" />
    <link rel="prev" title="Reference Counting" href="refcounting.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="utilities.html" title="Utilities"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="refcounting.html" title="Reference Counting"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="http://www.python.org/">Python</a> &raquo;</li>
        <li>
          <a href="../index.html">Python 2.7.5 documentation</a> &raquo;
        </li>

          <li><a href="index.html" accesskey="U">Python/C API Reference Manual</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="exception-handling">
<span id="exceptionhandling"></span><h1>Exception Handling<a class="headerlink" href="#exception-handling" title="Permalink to this headline">¶</a></h1>
<p>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 Unix <tt class="xref c c-data docutils literal"><span class="pre">errno</span></tt> variable:
there is a global indicator (per thread) of the last error that occurred.  Most
functions don&#8217;t clear this on success, but will set it to indicate the cause of
the error on failure.  Most functions also return an error indicator, usually
<em>NULL</em> if they are supposed to return a pointer, or <tt class="docutils literal"><span class="pre">-1</span></tt> if they return an
integer (exception: the <tt class="xref c c-func docutils literal"><span class="pre">PyArg_*()</span></tt> functions return <tt class="docutils literal"><span class="pre">1</span></tt> for success and
<tt class="docutils literal"><span class="pre">0</span></tt> for failure).</p>
<p>When a function must fail because some function it called failed, it generally
doesn&#8217;t set the error indicator; the function it called already set it.  It is
responsible for either handling the error and clearing the exception or
returning after cleaning up any resources it holds (such as object references or
memory allocations); it should <em>not</em> continue normally if it is not prepared to
handle the error.  If returning due to an error, it is important to indicate to
the caller that an error has been set.  If the error is not handled or carefully
propagated, additional calls into the Python/C API may not behave as intended
and may fail in mysterious ways.</p>
<p id="index-0">The error indicator consists of three Python objects corresponding to   the
Python variables <tt class="docutils literal"><span class="pre">sys.exc_type</span></tt>, <tt class="docutils literal"><span class="pre">sys.exc_value</span></tt> and <tt class="docutils literal"><span class="pre">sys.exc_traceback</span></tt>.
API functions exist to interact with the error indicator in various ways.  There
is a separate error indicator for each thread.</p>
<dl class="function">
<dt id="PyErr_PrintEx">
void <tt class="descname">PyErr_PrintEx</tt><big>(</big>int<em>&nbsp;set_sys_last_vars</em><big>)</big><a class="headerlink" href="#PyErr_PrintEx" title="Permalink to this definition">¶</a></dt>
<dd><p>Print a standard traceback to <tt class="docutils literal"><span class="pre">sys.stderr</span></tt> and clear the error indicator.
Call this function only when the error indicator is set.  (Otherwise it will
cause a fatal error!)</p>
<p>If <em>set_sys_last_vars</em> is nonzero, the variables <a class="reference internal" href="../library/sys.html#sys.last_type" title="sys.last_type"><tt class="xref py py-data docutils literal"><span class="pre">sys.last_type</span></tt></a>,
<a class="reference internal" href="../library/sys.html#sys.last_value" title="sys.last_value"><tt class="xref py py-data docutils literal"><span class="pre">sys.last_value</span></tt></a> and <a class="reference internal" href="../library/sys.html#sys.last_traceback" title="sys.last_traceback"><tt class="xref py py-data docutils literal"><span class="pre">sys.last_traceback</span></tt></a> will be set to the
type, value and traceback of the printed exception, respectively.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_Print">
void <tt class="descname">PyErr_Print</tt><big>(</big><big>)</big><a class="headerlink" href="#PyErr_Print" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for <tt class="docutils literal"><span class="pre">PyErr_PrintEx(1)</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_Occurred">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_Occurred</tt><big>(</big><big>)</big><a class="headerlink" href="#PyErr_Occurred" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Borrowed reference.</em><p>Test whether the error indicator is set.  If set, return the exception <em>type</em>
(the first argument to the last call to one of the <tt class="xref c c-func docutils literal"><span class="pre">PyErr_Set*()</span></tt>
functions or to <a class="reference internal" href="#PyErr_Restore" title="PyErr_Restore"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_Restore()</span></tt></a>).  If not set, return <em>NULL</em>.  You do not
own a reference to the return value, so you do not need to <a class="reference internal" href="refcounting.html#Py_DECREF" title="Py_DECREF"><tt class="xref c c-func docutils literal"><span class="pre">Py_DECREF()</span></tt></a>
it.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Do not compare the return value to a specific exception; use
<a class="reference internal" href="#PyErr_ExceptionMatches" title="PyErr_ExceptionMatches"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_ExceptionMatches()</span></tt></a> instead, shown below.  (The comparison could
easily fail since the exception may be an instance instead of a class, in the
case of a class exception, or it may the a subclass of the expected exception.)</p>
</div>
</dd></dl>

<dl class="function">
<dt id="PyErr_ExceptionMatches">
int <tt class="descname">PyErr_ExceptionMatches</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em><big>)</big><a class="headerlink" href="#PyErr_ExceptionMatches" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <tt class="docutils literal"><span class="pre">PyErr_GivenExceptionMatches(PyErr_Occurred(),</span> <span class="pre">exc)</span></tt>.  This
should only be called when an exception is actually set; a memory access
violation will occur if no exception has been raised.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_GivenExceptionMatches">
int <tt class="descname">PyErr_GivenExceptionMatches</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*given</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em><big>)</big><a class="headerlink" href="#PyErr_GivenExceptionMatches" title="Permalink to this definition">¶</a></dt>
<dd><p>Return true if the <em>given</em> exception matches the exception in <em>exc</em>.  If
<em>exc</em> is a class object, this also returns true when <em>given</em> is an instance
of a subclass.  If <em>exc</em> is a tuple, all exceptions in the tuple (and
recursively in subtuples) are searched for a match.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_NormalizeException">
void <tt class="descname">PyErr_NormalizeException</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>**exc, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>**val, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>**tb<big>)</big><a class="headerlink" href="#PyErr_NormalizeException" title="Permalink to this definition">¶</a></dt>
<dd><p>Under certain circumstances, the values returned by <a class="reference internal" href="#PyErr_Fetch" title="PyErr_Fetch"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_Fetch()</span></tt></a> below
can be &#8220;unnormalized&#8221;, meaning that <tt class="docutils literal"><span class="pre">*exc</span></tt> is a class object but <tt class="docutils literal"><span class="pre">*val</span></tt> is
not an instance of the  same class.  This function can be used to instantiate
the class in that case.  If the values are already normalized, nothing happens.
The delayed normalization is implemented to improve performance.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_Clear">
void <tt class="descname">PyErr_Clear</tt><big>(</big><big>)</big><a class="headerlink" href="#PyErr_Clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Clear the error indicator.  If the error indicator is not set, there is no
effect.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_Fetch">
void <tt class="descname">PyErr_Fetch</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;**ptype</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;**pvalue</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;**ptraceback</em><big>)</big><a class="headerlink" href="#PyErr_Fetch" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the error indicator into three variables whose addresses are passed.
If the error indicator is not set, set all three variables to <em>NULL</em>.  If it is
set, it will be cleared and you own a reference to each object retrieved.  The
value and traceback object may be <em>NULL</em> even when the type object is not.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is normally only used by code that needs to handle exceptions or
by code that needs to save and restore the error indicator temporarily.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="PyErr_Restore">
void <tt class="descname">PyErr_Restore</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*type</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*value</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*traceback</em><big>)</big><a class="headerlink" href="#PyErr_Restore" title="Permalink to this definition">¶</a></dt>
<dd><p>Set  the error indicator from the three objects.  If the error indicator is
already set, it is cleared first.  If the objects are <em>NULL</em>, the error
indicator is cleared.  Do not pass a <em>NULL</em> type and non-<em>NULL</em> value or
traceback.  The exception type should be a class.  Do not pass an invalid
exception type or value. (Violating these rules will cause subtle problems
later.)  This call takes away a reference to each object: you must own a
reference to each object before the call and after the call you no longer own
these references.  (If you don&#8217;t understand this, don&#8217;t use this function.  I
warned you.)</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is normally only used by code that needs to save and restore the
error indicator temporarily; use <a class="reference internal" href="#PyErr_Fetch" title="PyErr_Fetch"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_Fetch()</span></tt></a> to save the current
exception state.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetString">
void <tt class="descname">PyErr_SetString</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*type</em>, const char<em>&nbsp;*message</em><big>)</big><a class="headerlink" href="#PyErr_SetString" title="Permalink to this definition">¶</a></dt>
<dd><p>This is the most common way to set the error indicator.  The first argument
specifies the exception type; it is normally one of the standard exceptions,
e.g. <tt class="xref c c-data docutils literal"><span class="pre">PyExc_RuntimeError</span></tt>.  You need not increment its reference count.
The second argument is an error message; it is converted to a string object.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetObject">
void <tt class="descname">PyErr_SetObject</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*type</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*value</em><big>)</big><a class="headerlink" href="#PyErr_SetObject" title="Permalink to this definition">¶</a></dt>
<dd><p>This function is similar to <a class="reference internal" href="#PyErr_SetString" title="PyErr_SetString"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_SetString()</span></tt></a> but lets you specify an
arbitrary Python object for the &#8220;value&#8221; of the exception.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_Format">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_Format</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exception</em>, const char<em>&nbsp;*format</em>, ...<big>)</big><a class="headerlink" href="#PyErr_Format" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Always NULL.</em><p>This function sets the error indicator and returns <em>NULL</em>.  <em>exception</em>
should be a Python exception class.  The <em>format</em> and subsequent
parameters help format the error message; they have the same meaning and
values as in <a class="reference internal" href="string.html#PyString_FromFormat" title="PyString_FromFormat"><tt class="xref c c-func docutils literal"><span class="pre">PyString_FromFormat()</span></tt></a>.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetNone">
void <tt class="descname">PyErr_SetNone</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*type</em><big>)</big><a class="headerlink" href="#PyErr_SetNone" title="Permalink to this definition">¶</a></dt>
<dd><p>This is a shorthand for <tt class="docutils literal"><span class="pre">PyErr_SetObject(type,</span> <span class="pre">Py_None)</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_BadArgument">
int <tt class="descname">PyErr_BadArgument</tt><big>(</big><big>)</big><a class="headerlink" href="#PyErr_BadArgument" title="Permalink to this definition">¶</a></dt>
<dd><p>This is a shorthand for <tt class="docutils literal"><span class="pre">PyErr_SetString(PyExc_TypeError,</span> <span class="pre">message)</span></tt>, where
<em>message</em> indicates that a built-in operation was invoked with an illegal
argument.  It is mostly for internal use.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_NoMemory">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_NoMemory</tt><big>(</big><big>)</big><a class="headerlink" href="#PyErr_NoMemory" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Always NULL.</em><p>This is a shorthand for <tt class="docutils literal"><span class="pre">PyErr_SetNone(PyExc_MemoryError)</span></tt>; it returns <em>NULL</em>
so an object allocation function can write <tt class="docutils literal"><span class="pre">return</span> <span class="pre">PyErr_NoMemory();</span></tt> when it
runs out of memory.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetFromErrno">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_SetFromErrno</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*type</em><big>)</big><a class="headerlink" href="#PyErr_SetFromErrno" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Always NULL.</em><p id="index-1">This is a convenience function to raise an exception when a C library function
has returned an error and set the C variable <tt class="xref c c-data docutils literal"><span class="pre">errno</span></tt>.  It constructs a
tuple object whose first item is the integer <tt class="xref c c-data docutils literal"><span class="pre">errno</span></tt> value and whose
second item is the corresponding error message (gotten from <tt class="xref c c-func docutils literal"><span class="pre">strerror()</span></tt>),
and then calls <tt class="docutils literal"><span class="pre">PyErr_SetObject(type,</span> <span class="pre">object)</span></tt>.  On Unix, when the
<tt class="xref c c-data docutils literal"><span class="pre">errno</span></tt> value is <tt class="xref py py-const docutils literal"><span class="pre">EINTR</span></tt>, indicating an interrupted system call,
this calls <a class="reference internal" href="#PyErr_CheckSignals" title="PyErr_CheckSignals"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_CheckSignals()</span></tt></a>, and if that set the error indicator,
leaves it set to that.  The function always returns <em>NULL</em>, so a wrapper
function around a system call can write <tt class="docutils literal"><span class="pre">return</span> <span class="pre">PyErr_SetFromErrno(type);</span></tt>
when the system call returns an error.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetFromErrnoWithFilenameObject">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_SetFromErrnoWithFilenameObject</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*type</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*filenameObject</em><big>)</big><a class="headerlink" href="#PyErr_SetFromErrnoWithFilenameObject" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#PyErr_SetFromErrno" title="PyErr_SetFromErrno"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_SetFromErrno()</span></tt></a>, with the additional behavior that if
<em>filenameObject</em> is not <em>NULL</em>, it is passed to the constructor of <em>type</em> as
a third parameter.  In the case of exceptions such as <a class="reference internal" href="../library/exceptions.html#exceptions.IOError" title="exceptions.IOError"><tt class="xref py py-exc docutils literal"><span class="pre">IOError</span></tt></a> and
<a class="reference internal" href="../library/exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a>, this is used to define the <tt class="xref py py-attr docutils literal"><span class="pre">filename</span></tt> attribute of the
exception instance.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetFromErrnoWithFilename">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_SetFromErrnoWithFilename</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*type</em>, const char<em>&nbsp;*filename</em><big>)</big><a class="headerlink" href="#PyErr_SetFromErrnoWithFilename" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Always NULL.</em><p>Similar to <a class="reference internal" href="#PyErr_SetFromErrnoWithFilenameObject" title="PyErr_SetFromErrnoWithFilenameObject"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_SetFromErrnoWithFilenameObject()</span></tt></a>, but the filename
is given as a C string.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetFromWindowsErr">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_SetFromWindowsErr</tt><big>(</big>int<em>&nbsp;ierr</em><big>)</big><a class="headerlink" href="#PyErr_SetFromWindowsErr" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Always NULL.</em><p>This is a convenience function to raise <a class="reference internal" href="../library/exceptions.html#exceptions.WindowsError" title="exceptions.WindowsError"><tt class="xref py py-exc docutils literal"><span class="pre">WindowsError</span></tt></a>. If called with
<em>ierr</em> of <tt class="xref c c-data docutils literal"><span class="pre">0</span></tt>, the error code returned by a call to <tt class="xref c c-func docutils literal"><span class="pre">GetLastError()</span></tt>
is used instead.  It calls the Win32 function <tt class="xref c c-func docutils literal"><span class="pre">FormatMessage()</span></tt> to retrieve
the Windows description of error code given by <em>ierr</em> or <tt class="xref c c-func docutils literal"><span class="pre">GetLastError()</span></tt>,
then it constructs a tuple object whose first item is the <em>ierr</em> value and whose
second item is the corresponding error message (gotten from
<tt class="xref c c-func docutils literal"><span class="pre">FormatMessage()</span></tt>), and then calls <tt class="docutils literal"><span class="pre">PyErr_SetObject(PyExc_WindowsError,</span>
<span class="pre">object)</span></tt>. This function always returns <em>NULL</em>. Availability: Windows.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetExcFromWindowsErr">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_SetExcFromWindowsErr</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*type</em>, int<em>&nbsp;ierr</em><big>)</big><a class="headerlink" href="#PyErr_SetExcFromWindowsErr" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Always NULL.</em><p>Similar to <a class="reference internal" href="#PyErr_SetFromWindowsErr" title="PyErr_SetFromWindowsErr"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_SetFromWindowsErr()</span></tt></a>, with an additional parameter
specifying the exception type to be raised. Availability: Windows.</p>
<p class="versionadded">
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetFromWindowsErrWithFilenameObject">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_SetFromWindowsErrWithFilenameObject</tt><big>(</big>int<em>&nbsp;ierr</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*filenameObject</em><big>)</big><a class="headerlink" href="#PyErr_SetFromWindowsErrWithFilenameObject" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#PyErr_SetFromWindowsErr" title="PyErr_SetFromWindowsErr"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_SetFromWindowsErr()</span></tt></a>, with the additional behavior that
if <em>filenameObject</em> is not <em>NULL</em>, it is passed to the constructor of
<a class="reference internal" href="../library/exceptions.html#exceptions.WindowsError" title="exceptions.WindowsError"><tt class="xref py py-exc docutils literal"><span class="pre">WindowsError</span></tt></a> as a third parameter. Availability: Windows.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetFromWindowsErrWithFilename">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_SetFromWindowsErrWithFilename</tt><big>(</big>int<em>&nbsp;ierr</em>, const char<em>&nbsp;*filename</em><big>)</big><a class="headerlink" href="#PyErr_SetFromWindowsErrWithFilename" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Always NULL.</em><p>Similar to <a class="reference internal" href="#PyErr_SetFromWindowsErrWithFilenameObject" title="PyErr_SetFromWindowsErrWithFilenameObject"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_SetFromWindowsErrWithFilenameObject()</span></tt></a>, but the
filename is given as a C string. Availability: Windows.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetExcFromWindowsErrWithFilenameObject">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_SetExcFromWindowsErrWithFilenameObject</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*type</em>, int<em>&nbsp;ierr</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*filename</em><big>)</big><a class="headerlink" href="#PyErr_SetExcFromWindowsErrWithFilenameObject" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#PyErr_SetFromWindowsErrWithFilenameObject" title="PyErr_SetFromWindowsErrWithFilenameObject"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_SetFromWindowsErrWithFilenameObject()</span></tt></a>, with an
additional parameter specifying the exception type to be raised.
Availability: Windows.</p>
<p class="versionadded">
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetExcFromWindowsErrWithFilename">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_SetExcFromWindowsErrWithFilename</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*type</em>, int<em>&nbsp;ierr</em>, const char<em>&nbsp;*filename</em><big>)</big><a class="headerlink" href="#PyErr_SetExcFromWindowsErrWithFilename" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Always NULL.</em><p>Similar to <a class="reference internal" href="#PyErr_SetFromWindowsErrWithFilename" title="PyErr_SetFromWindowsErrWithFilename"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_SetFromWindowsErrWithFilename()</span></tt></a>, with an additional
parameter specifying the exception type to be raised. Availability: Windows.</p>
<p class="versionadded">
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="PyErr_BadInternalCall">
void <tt class="descname">PyErr_BadInternalCall</tt><big>(</big><big>)</big><a class="headerlink" href="#PyErr_BadInternalCall" title="Permalink to this definition">¶</a></dt>
<dd><p>This is a shorthand for <tt class="docutils literal"><span class="pre">PyErr_SetString(PyExc_SystemError,</span> <span class="pre">message)</span></tt>,
where <em>message</em> indicates that an internal operation (e.g. a Python/C API
function) was invoked with an illegal argument.  It is mostly for internal
use.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_WarnEx">
int <tt class="descname">PyErr_WarnEx</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*category</em>, char<em>&nbsp;*message</em>, int<em>&nbsp;stacklevel</em><big>)</big><a class="headerlink" href="#PyErr_WarnEx" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a warning message.  The <em>category</em> argument is a warning category (see
below) or <em>NULL</em>; the <em>message</em> argument is a message string.  <em>stacklevel</em> is a
positive number giving a number of stack frames; the warning will be issued from
the  currently executing line of code in that stack frame.  A <em>stacklevel</em> of 1
is the function calling <a class="reference internal" href="#PyErr_WarnEx" title="PyErr_WarnEx"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_WarnEx()</span></tt></a>, 2 is  the function above that,
and so forth.</p>
<p>This function normally prints a warning message to <em>sys.stderr</em>; however, it is
also possible that the user has specified that warnings are to be turned into
errors, and in that case this will raise an exception.  It is also possible that
the function raises an exception because of a problem with the warning machinery
(the implementation imports the <a class="reference internal" href="../library/warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><tt class="xref py py-mod docutils literal"><span class="pre">warnings</span></tt></a> module to do the heavy lifting).
The return value is <tt class="docutils literal"><span class="pre">0</span></tt> if no exception is raised, or <tt class="docutils literal"><span class="pre">-1</span></tt> if an exception
is raised.  (It is not possible to determine whether a warning message is
actually printed, nor what the reason is for the exception; this is
intentional.)  If an exception is raised, the caller should do its normal
exception handling (for example, <a class="reference internal" href="refcounting.html#Py_DECREF" title="Py_DECREF"><tt class="xref c c-func docutils literal"><span class="pre">Py_DECREF()</span></tt></a> owned references and return
an error value).</p>
<p>Warning categories must be subclasses of <tt class="xref c c-data docutils literal"><span class="pre">Warning</span></tt>; the default warning
category is <tt class="xref c c-data docutils literal"><span class="pre">RuntimeWarning</span></tt>.  The standard Python warning categories are
available as global variables whose names are <tt class="docutils literal"><span class="pre">PyExc_</span></tt> followed by the Python
exception name. These have the type <a class="reference internal" href="structures.html#PyObject" title="PyObject"><tt class="xref c c-type docutils literal"><span class="pre">PyObject*</span></tt></a>; they are all class
objects. Their names are <tt class="xref c c-data docutils literal"><span class="pre">PyExc_Warning</span></tt>, <tt class="xref c c-data docutils literal"><span class="pre">PyExc_UserWarning</span></tt>,
<tt class="xref c c-data docutils literal"><span class="pre">PyExc_UnicodeWarning</span></tt>, <tt class="xref c c-data docutils literal"><span class="pre">PyExc_DeprecationWarning</span></tt>,
<tt class="xref c c-data docutils literal"><span class="pre">PyExc_SyntaxWarning</span></tt>, <tt class="xref c c-data docutils literal"><span class="pre">PyExc_RuntimeWarning</span></tt>, and
<tt class="xref c c-data docutils literal"><span class="pre">PyExc_FutureWarning</span></tt>.  <tt class="xref c c-data docutils literal"><span class="pre">PyExc_Warning</span></tt> is a subclass of
<tt class="xref c c-data docutils literal"><span class="pre">PyExc_Exception</span></tt>; the other warning categories are subclasses of
<tt class="xref c c-data docutils literal"><span class="pre">PyExc_Warning</span></tt>.</p>
<p>For information about warning control, see the documentation for the
<a class="reference internal" href="../library/warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><tt class="xref py py-mod docutils literal"><span class="pre">warnings</span></tt></a> module and the <a class="reference internal" href="../using/cmdline.html#cmdoption-W"><em class="xref std std-option">-W</em></a> option in the command line
documentation.  There is no C API for warning control.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_Warn">
int <tt class="descname">PyErr_Warn</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*category</em>, char<em>&nbsp;*message</em><big>)</big><a class="headerlink" href="#PyErr_Warn" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a warning message.  The <em>category</em> argument is a warning category (see
below) or <em>NULL</em>; the <em>message</em> argument is a message string.  The warning will
appear to be issued from the function calling <a class="reference internal" href="#PyErr_Warn" title="PyErr_Warn"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_Warn()</span></tt></a>, equivalent to
calling <a class="reference internal" href="#PyErr_WarnEx" title="PyErr_WarnEx"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_WarnEx()</span></tt></a> with a <em>stacklevel</em> of 1.</p>
<p>Deprecated; use <a class="reference internal" href="#PyErr_WarnEx" title="PyErr_WarnEx"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_WarnEx()</span></tt></a> instead.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_WarnExplicit">
int <tt class="descname">PyErr_WarnExplicit</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*category</em>, const char<em>&nbsp;*message</em>, const char<em>&nbsp;*filename</em>, int<em>&nbsp;lineno</em>, const char<em>&nbsp;*module</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*registry</em><big>)</big><a class="headerlink" href="#PyErr_WarnExplicit" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a warning message with explicit control over all warning attributes.  This
is a straightforward wrapper around the Python function
<a class="reference internal" href="../library/warnings.html#warnings.warn_explicit" title="warnings.warn_explicit"><tt class="xref py py-func docutils literal"><span class="pre">warnings.warn_explicit()</span></tt></a>, see there for more information.  The <em>module</em>
and <em>registry</em> arguments may be set to <em>NULL</em> to get the default effect
described there.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_WarnPy3k">
int <tt class="descname">PyErr_WarnPy3k</tt><big>(</big>char<em>&nbsp;*message</em>, int<em>&nbsp;stacklevel</em><big>)</big><a class="headerlink" href="#PyErr_WarnPy3k" title="Permalink to this definition">¶</a></dt>
<dd><p>Issue a <a class="reference internal" href="../library/exceptions.html#exceptions.DeprecationWarning" title="exceptions.DeprecationWarning"><tt class="xref py py-exc docutils literal"><span class="pre">DeprecationWarning</span></tt></a> with the given <em>message</em> and <em>stacklevel</em>
if the <tt class="xref c c-data docutils literal"><span class="pre">Py_Py3kWarningFlag</span></tt> flag is enabled.</p>
<p class="versionadded">
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="PyErr_CheckSignals">
int <tt class="descname">PyErr_CheckSignals</tt><big>(</big><big>)</big><a class="headerlink" href="#PyErr_CheckSignals" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-2">This function interacts with Python&#8217;s signal handling.  It checks whether a
signal has been sent to the processes 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."><tt class="xref py py-mod docutils literal"><span class="pre">signal</span></tt></a> module is supported, this can invoke a
signal handler written in Python.  In all cases, the default effect for
<tt class="xref py py-const docutils literal"><span class="pre">SIGINT</span></tt> is to raise the  <a class="reference internal" href="../library/exceptions.html#exceptions.KeyboardInterrupt" title="exceptions.KeyboardInterrupt"><tt class="xref py py-exc docutils literal"><span class="pre">KeyboardInterrupt</span></tt></a> exception.  If an
exception is raised the error indicator is set and the function returns <tt class="docutils literal"><span class="pre">-1</span></tt>;
otherwise the function returns <tt class="docutils literal"><span class="pre">0</span></tt>.  The error indicator may or may not be
cleared if it was previously set.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_SetInterrupt">
void <tt class="descname">PyErr_SetInterrupt</tt><big>(</big><big>)</big><a class="headerlink" href="#PyErr_SetInterrupt" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-3">This function simulates the effect of a <tt class="xref py py-const docutils literal"><span class="pre">SIGINT</span></tt> signal arriving &#8212; the
next time <a class="reference internal" href="#PyErr_CheckSignals" title="PyErr_CheckSignals"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_CheckSignals()</span></tt></a> is called,  <a class="reference internal" href="../library/exceptions.html#exceptions.KeyboardInterrupt" title="exceptions.KeyboardInterrupt"><tt class="xref py py-exc docutils literal"><span class="pre">KeyboardInterrupt</span></tt></a> will
be raised.  It may be called without holding the interpreter lock.</p>
</dd></dl>

<dl class="function">
<dt id="PySignal_SetWakeupFd">
int <tt class="descname">PySignal_SetWakeupFd</tt><big>(</big>int<em>&nbsp;fd</em><big>)</big><a class="headerlink" href="#PySignal_SetWakeupFd" title="Permalink to this definition">¶</a></dt>
<dd><p>This utility function specifies a file descriptor to which a <tt class="docutils literal"><span class="pre">'\0'</span></tt> byte will
be written whenever a signal is received.  It returns the previous such file
descriptor.  The value <tt class="docutils literal"><span class="pre">-1</span></tt> disables the feature; this is the initial state.
This is equivalent to <a class="reference internal" href="../library/signal.html#signal.set_wakeup_fd" title="signal.set_wakeup_fd"><tt class="xref py py-func docutils literal"><span class="pre">signal.set_wakeup_fd()</span></tt></a> in Python, but without any
error checking.  <em>fd</em> should be a valid file descriptor.  The function should
only be called from the main thread.</p>
<p class="versionadded">
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="PyErr_NewException">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_NewException</tt><big>(</big>char<em>&nbsp;*name</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*base</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*dict</em><big>)</big><a class="headerlink" href="#PyErr_NewException" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>This utility function creates and returns a new exception class. The <em>name</em>
argument must be the name of the new exception, a C string of the form
<tt class="docutils literal"><span class="pre">module.classname</span></tt>.  The <em>base</em> and <em>dict</em> arguments are normally <em>NULL</em>.
This creates a class object derived from <a class="reference internal" href="../library/exceptions.html#exceptions.Exception" title="exceptions.Exception"><tt class="xref py py-exc docutils literal"><span class="pre">Exception</span></tt></a> (accessible in C as
<tt class="xref c c-data docutils literal"><span class="pre">PyExc_Exception</span></tt>).</p>
<p>The <tt class="xref py py-attr docutils literal"><span class="pre">__module__</span></tt> attribute of the new class is set to the first part (up
to the last dot) of the <em>name</em> argument, and the class name is set to the last
part (after the last dot).  The <em>base</em> argument can be used to specify alternate
base classes; it can either be only one class or a tuple of classes. The <em>dict</em>
argument can be used to specify a dictionary of class variables and methods.</p>
</dd></dl>

<dl class="function">
<dt id="PyErr_NewExceptionWithDoc">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyErr_NewExceptionWithDoc</tt><big>(</big>char<em>&nbsp;*name</em>, char<em>&nbsp;*doc</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*base</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*dict</em><big>)</big><a class="headerlink" href="#PyErr_NewExceptionWithDoc" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Same as <a class="reference internal" href="#PyErr_NewException" title="PyErr_NewException"><tt class="xref c c-func docutils literal"><span class="pre">PyErr_NewException()</span></tt></a>, except that the new exception class can
easily be given a docstring: If <em>doc</em> is non-<em>NULL</em>, it will be used as the
docstring for the exception class.</p>
<p class="versionadded">
<span class="versionmodified">New in version 2.7.</span></p>
</dd></dl>

<dl class="function">
<dt id="PyErr_WriteUnraisable">
void <tt class="descname">PyErr_WriteUnraisable</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*obj</em><big>)</big><a class="headerlink" href="#PyErr_WriteUnraisable" title="Permalink to this definition">¶</a></dt>
<dd><p>This utility function prints a warning message to <tt class="docutils literal"><span class="pre">sys.stderr</span></tt> when an
exception has been set but it is impossible for the interpreter to actually
raise the exception.  It is used, for example, when an exception occurs in an
<a class="reference internal" href="../reference/datamodel.html#object.__del__" title="object.__del__"><tt class="xref py py-meth docutils literal"><span class="pre">__del__()</span></tt></a> method.</p>
<p>The function is called with a single argument <em>obj</em> that identifies the context
in which the unraisable exception occurred. The repr of <em>obj</em> will be printed in
the warning message.</p>
</dd></dl>

<div class="section" id="unicode-exception-objects">
<span id="unicodeexceptions"></span><h2>Unicode Exception Objects<a class="headerlink" href="#unicode-exception-objects" title="Permalink to this headline">¶</a></h2>
<p>The following functions are used to create and modify Unicode exceptions from C.</p>
<dl class="function">
<dt id="PyUnicodeDecodeError_Create">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyUnicodeDecodeError_Create</tt><big>(</big>const char<em>&nbsp;*encoding</em>, const char<em>&nbsp;*object</em>, Py_ssize_t<em>&nbsp;length</em>, Py_ssize_t<em>&nbsp;start</em>, Py_ssize_t<em>&nbsp;end</em>, const char<em>&nbsp;*reason</em><big>)</big><a class="headerlink" href="#PyUnicodeDecodeError_Create" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a <tt class="xref py py-class docutils literal"><span class="pre">UnicodeDecodeError</span></tt> object with the attributes <em>encoding</em>,
<em>object</em>, <em>length</em>, <em>start</em>, <em>end</em> and <em>reason</em>.</p>
</dd></dl>

<dl class="function">
<dt id="PyUnicodeEncodeError_Create">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyUnicodeEncodeError_Create</tt><big>(</big>const char<em>&nbsp;*encoding</em>, const <a class="reference internal" href="unicode.html#Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*object</em>, Py_ssize_t<em>&nbsp;length</em>, Py_ssize_t<em>&nbsp;start</em>, Py_ssize_t<em>&nbsp;end</em>, const char<em>&nbsp;*reason</em><big>)</big><a class="headerlink" href="#PyUnicodeEncodeError_Create" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a <tt class="xref py py-class docutils literal"><span class="pre">UnicodeEncodeError</span></tt> object with the attributes <em>encoding</em>,
<em>object</em>, <em>length</em>, <em>start</em>, <em>end</em> and <em>reason</em>.</p>
</dd></dl>

<dl class="function">
<dt id="PyUnicodeTranslateError_Create">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyUnicodeTranslateError_Create</tt><big>(</big>const <a class="reference internal" href="unicode.html#Py_UNICODE" title="Py_UNICODE">Py_UNICODE</a><em>&nbsp;*object</em>, Py_ssize_t<em>&nbsp;length</em>, Py_ssize_t<em>&nbsp;start</em>, Py_ssize_t<em>&nbsp;end</em>, const char<em>&nbsp;*reason</em><big>)</big><a class="headerlink" href="#PyUnicodeTranslateError_Create" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a <tt class="xref py py-class docutils literal"><span class="pre">UnicodeTranslateError</span></tt> object with the attributes <em>object</em>,
<em>length</em>, <em>start</em>, <em>end</em> and <em>reason</em>.</p>
</dd></dl>

<dl class="function">
<dt id="PyUnicodeDecodeError_GetEncoding">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyUnicodeDecodeError_GetEncoding</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em><big>)</big><a class="headerlink" href="#PyUnicodeDecodeError_GetEncoding" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeEncodeError_GetEncoding">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyUnicodeEncodeError_GetEncoding</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em><big>)</big><a class="headerlink" href="#PyUnicodeEncodeError_GetEncoding" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the <em>encoding</em> attribute of the given exception object.</p>
</dd></dl>

<dl class="function">
<dt id="PyUnicodeDecodeError_GetObject">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyUnicodeDecodeError_GetObject</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em><big>)</big><a class="headerlink" href="#PyUnicodeDecodeError_GetObject" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeEncodeError_GetObject">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyUnicodeEncodeError_GetObject</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em><big>)</big><a class="headerlink" href="#PyUnicodeEncodeError_GetObject" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeTranslateError_GetObject">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyUnicodeTranslateError_GetObject</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em><big>)</big><a class="headerlink" href="#PyUnicodeTranslateError_GetObject" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the <em>object</em> attribute of the given exception object.</p>
</dd></dl>

<dl class="function">
<dt id="PyUnicodeDecodeError_GetStart">
int <tt class="descname">PyUnicodeDecodeError_GetStart</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, Py_ssize_t<em>&nbsp;*start</em><big>)</big><a class="headerlink" href="#PyUnicodeDecodeError_GetStart" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeEncodeError_GetStart">
int <tt class="descname">PyUnicodeEncodeError_GetStart</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, Py_ssize_t<em>&nbsp;*start</em><big>)</big><a class="headerlink" href="#PyUnicodeEncodeError_GetStart" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeTranslateError_GetStart">
int <tt class="descname">PyUnicodeTranslateError_GetStart</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, Py_ssize_t<em>&nbsp;*start</em><big>)</big><a class="headerlink" href="#PyUnicodeTranslateError_GetStart" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the <em>start</em> attribute of the given exception object and place it into
<em>*start</em>.  <em>start</em> must not be <em>NULL</em>.  Return <tt class="docutils literal"><span class="pre">0</span></tt> on success, <tt class="docutils literal"><span class="pre">-1</span></tt> on
failure.</p>
</dd></dl>

<dl class="function">
<dt id="PyUnicodeDecodeError_SetStart">
int <tt class="descname">PyUnicodeDecodeError_SetStart</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, Py_ssize_t<em>&nbsp;start</em><big>)</big><a class="headerlink" href="#PyUnicodeDecodeError_SetStart" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeEncodeError_SetStart">
int <tt class="descname">PyUnicodeEncodeError_SetStart</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, Py_ssize_t<em>&nbsp;start</em><big>)</big><a class="headerlink" href="#PyUnicodeEncodeError_SetStart" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeTranslateError_SetStart">
int <tt class="descname">PyUnicodeTranslateError_SetStart</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, Py_ssize_t<em>&nbsp;start</em><big>)</big><a class="headerlink" href="#PyUnicodeTranslateError_SetStart" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the <em>start</em> attribute of the given exception object to <em>start</em>.  Return
<tt class="docutils literal"><span class="pre">0</span></tt> on success, <tt class="docutils literal"><span class="pre">-1</span></tt> on failure.</p>
</dd></dl>

<dl class="function">
<dt id="PyUnicodeDecodeError_GetEnd">
int <tt class="descname">PyUnicodeDecodeError_GetEnd</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, Py_ssize_t<em>&nbsp;*end</em><big>)</big><a class="headerlink" href="#PyUnicodeDecodeError_GetEnd" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeEncodeError_GetEnd">
int <tt class="descname">PyUnicodeEncodeError_GetEnd</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, Py_ssize_t<em>&nbsp;*end</em><big>)</big><a class="headerlink" href="#PyUnicodeEncodeError_GetEnd" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeTranslateError_GetEnd">
int <tt class="descname">PyUnicodeTranslateError_GetEnd</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, Py_ssize_t<em>&nbsp;*end</em><big>)</big><a class="headerlink" href="#PyUnicodeTranslateError_GetEnd" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the <em>end</em> attribute of the given exception object and place it into
<em>*end</em>.  <em>end</em> must not be <em>NULL</em>.  Return <tt class="docutils literal"><span class="pre">0</span></tt> on success, <tt class="docutils literal"><span class="pre">-1</span></tt> on
failure.</p>
</dd></dl>

<dl class="function">
<dt id="PyUnicodeDecodeError_SetEnd">
int <tt class="descname">PyUnicodeDecodeError_SetEnd</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, Py_ssize_t<em>&nbsp;end</em><big>)</big><a class="headerlink" href="#PyUnicodeDecodeError_SetEnd" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeEncodeError_SetEnd">
int <tt class="descname">PyUnicodeEncodeError_SetEnd</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, Py_ssize_t<em>&nbsp;end</em><big>)</big><a class="headerlink" href="#PyUnicodeEncodeError_SetEnd" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeTranslateError_SetEnd">
int <tt class="descname">PyUnicodeTranslateError_SetEnd</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, Py_ssize_t<em>&nbsp;end</em><big>)</big><a class="headerlink" href="#PyUnicodeTranslateError_SetEnd" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the <em>end</em> attribute of the given exception object to <em>end</em>.  Return <tt class="docutils literal"><span class="pre">0</span></tt>
on success, <tt class="docutils literal"><span class="pre">-1</span></tt> on failure.</p>
</dd></dl>

<dl class="function">
<dt id="PyUnicodeDecodeError_GetReason">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyUnicodeDecodeError_GetReason</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em><big>)</big><a class="headerlink" href="#PyUnicodeDecodeError_GetReason" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeEncodeError_GetReason">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyUnicodeEncodeError_GetReason</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em><big>)</big><a class="headerlink" href="#PyUnicodeEncodeError_GetReason" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeTranslateError_GetReason">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyUnicodeTranslateError_GetReason</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em><big>)</big><a class="headerlink" href="#PyUnicodeTranslateError_GetReason" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the <em>reason</em> attribute of the given exception object.</p>
</dd></dl>

<dl class="function">
<dt id="PyUnicodeDecodeError_SetReason">
int <tt class="descname">PyUnicodeDecodeError_SetReason</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, const char<em>&nbsp;*reason</em><big>)</big><a class="headerlink" href="#PyUnicodeDecodeError_SetReason" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeEncodeError_SetReason">
int <tt class="descname">PyUnicodeEncodeError_SetReason</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, const char<em>&nbsp;*reason</em><big>)</big><a class="headerlink" href="#PyUnicodeEncodeError_SetReason" title="Permalink to this definition">¶</a></dt>
<dt id="PyUnicodeTranslateError_SetReason">
int <tt class="descname">PyUnicodeTranslateError_SetReason</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*exc</em>, const char<em>&nbsp;*reason</em><big>)</big><a class="headerlink" href="#PyUnicodeTranslateError_SetReason" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the <em>reason</em> attribute of the given exception object to <em>reason</em>.  Return
<tt class="docutils literal"><span class="pre">0</span></tt> on success, <tt class="docutils literal"><span class="pre">-1</span></tt> on failure.</p>
</dd></dl>

</div>
<div class="section" id="recursion-control">
<h2>Recursion Control<a class="headerlink" href="#recursion-control" title="Permalink to this headline">¶</a></h2>
<p>These two functions provide a way to perform safe recursive calls at the C
level, both in the core and in extension modules.  They are needed if the
recursive code does not necessarily invoke Python code (which tracks its
recursion depth automatically).</p>
<dl class="function">
<dt id="Py_EnterRecursiveCall">
int <tt class="descname">Py_EnterRecursiveCall</tt><big>(</big>char<em>&nbsp;*where</em><big>)</big><a class="headerlink" href="#Py_EnterRecursiveCall" title="Permalink to this definition">¶</a></dt>
<dd><p>Marks a point where a recursive C-level call is about to be performed.</p>
<p>If <tt class="xref py py-const docutils literal"><span class="pre">USE_STACKCHECK</span></tt> is defined, this function checks if the OS
stack overflowed using <a class="reference internal" href="sys.html#PyOS_CheckStack" title="PyOS_CheckStack"><tt class="xref c c-func docutils literal"><span class="pre">PyOS_CheckStack()</span></tt></a>.  In this is the case, it
sets a <a class="reference internal" href="../library/exceptions.html#exceptions.MemoryError" title="exceptions.MemoryError"><tt class="xref py py-exc docutils literal"><span class="pre">MemoryError</span></tt></a> and returns a nonzero value.</p>
<p>The function then checks if the recursion limit is reached.  If this is the
case, a <a class="reference internal" href="../library/exceptions.html#exceptions.RuntimeError" title="exceptions.RuntimeError"><tt class="xref py py-exc docutils literal"><span class="pre">RuntimeError</span></tt></a> is set and a nonzero value is returned.
Otherwise, zero is returned.</p>
<p><em>where</em> should be a string such as <tt class="docutils literal"><span class="pre">&quot;</span> <span class="pre">in</span> <span class="pre">instance</span> <span class="pre">check&quot;</span></tt> to be
concatenated to the <a class="reference internal" href="../library/exceptions.html#exceptions.RuntimeError" title="exceptions.RuntimeError"><tt class="xref py py-exc docutils literal"><span class="pre">RuntimeError</span></tt></a> message caused by the recursion depth
limit.</p>
</dd></dl>

<dl class="function">
<dt id="Py_LeaveRecursiveCall">
void <tt class="descname">Py_LeaveRecursiveCall</tt><big>(</big><big>)</big><a class="headerlink" href="#Py_LeaveRecursiveCall" title="Permalink to this definition">¶</a></dt>
<dd><p>Ends a <a class="reference internal" href="#Py_EnterRecursiveCall" title="Py_EnterRecursiveCall"><tt class="xref c c-func docutils literal"><span class="pre">Py_EnterRecursiveCall()</span></tt></a>.  Must be called once for each
<em>successful</em> invocation of <a class="reference internal" href="#Py_EnterRecursiveCall" title="Py_EnterRecursiveCall"><tt class="xref c c-func docutils literal"><span class="pre">Py_EnterRecursiveCall()</span></tt></a>.</p>
</dd></dl>

</div>
<div class="section" id="standard-exceptions">
<span id="standardexceptions"></span><h2>Standard Exceptions<a class="headerlink" href="#standard-exceptions" title="Permalink to this headline">¶</a></h2>
<p>All standard Python exceptions are available as global variables whose names are
<tt class="docutils literal"><span class="pre">PyExc_</span></tt> followed by the Python exception name.  These have the type
<a class="reference internal" href="structures.html#PyObject" title="PyObject"><tt class="xref c c-type docutils literal"><span class="pre">PyObject*</span></tt></a>; they are all class objects.  For completeness, here are all
the variables:</p>
<table border="1" class="docutils">
<colgroup>
<col width="49%" />
<col width="37%" />
<col width="13%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">C Name</th>
<th class="head">Python Name</th>
<th class="head">Notes</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_BaseException</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.BaseException" title="exceptions.BaseException"><tt class="xref py py-exc docutils literal"><span class="pre">BaseException</span></tt></a></td>
<td>(1), (4)</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_Exception</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.Exception" title="exceptions.Exception"><tt class="xref py py-exc docutils literal"><span class="pre">Exception</span></tt></a></td>
<td>(1)</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_StandardError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.StandardError" title="exceptions.StandardError"><tt class="xref py py-exc docutils literal"><span class="pre">StandardError</span></tt></a></td>
<td>(1)</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_ArithmeticError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.ArithmeticError" title="exceptions.ArithmeticError"><tt class="xref py py-exc docutils literal"><span class="pre">ArithmeticError</span></tt></a></td>
<td>(1)</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_LookupError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.LookupError" title="exceptions.LookupError"><tt class="xref py py-exc docutils literal"><span class="pre">LookupError</span></tt></a></td>
<td>(1)</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_AssertionError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.AssertionError" title="exceptions.AssertionError"><tt class="xref py py-exc docutils literal"><span class="pre">AssertionError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_AttributeError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.AttributeError" title="exceptions.AttributeError"><tt class="xref py py-exc docutils literal"><span class="pre">AttributeError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_EOFError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.EOFError" title="exceptions.EOFError"><tt class="xref py py-exc docutils literal"><span class="pre">EOFError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_EnvironmentError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.EnvironmentError" title="exceptions.EnvironmentError"><tt class="xref py py-exc docutils literal"><span class="pre">EnvironmentError</span></tt></a></td>
<td>(1)</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_FloatingPointError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.FloatingPointError" title="exceptions.FloatingPointError"><tt class="xref py py-exc docutils literal"><span class="pre">FloatingPointError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_IOError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.IOError" title="exceptions.IOError"><tt class="xref py py-exc docutils literal"><span class="pre">IOError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_ImportError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.ImportError" title="exceptions.ImportError"><tt class="xref py py-exc docutils literal"><span class="pre">ImportError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_IndexError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.IndexError" title="exceptions.IndexError"><tt class="xref py py-exc docutils literal"><span class="pre">IndexError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_KeyError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.KeyError" title="exceptions.KeyError"><tt class="xref py py-exc docutils literal"><span class="pre">KeyError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_KeyboardInterrupt</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.KeyboardInterrupt" title="exceptions.KeyboardInterrupt"><tt class="xref py py-exc docutils literal"><span class="pre">KeyboardInterrupt</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_MemoryError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.MemoryError" title="exceptions.MemoryError"><tt class="xref py py-exc docutils literal"><span class="pre">MemoryError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_NameError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.NameError" title="exceptions.NameError"><tt class="xref py py-exc docutils literal"><span class="pre">NameError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_NotImplementedError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.NotImplementedError" title="exceptions.NotImplementedError"><tt class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_OSError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_OverflowError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.OverflowError" title="exceptions.OverflowError"><tt class="xref py py-exc docutils literal"><span class="pre">OverflowError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_ReferenceError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.ReferenceError" title="exceptions.ReferenceError"><tt class="xref py py-exc docutils literal"><span class="pre">ReferenceError</span></tt></a></td>
<td>(2)</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_RuntimeError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.RuntimeError" title="exceptions.RuntimeError"><tt class="xref py py-exc docutils literal"><span class="pre">RuntimeError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_SyntaxError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.SyntaxError" title="exceptions.SyntaxError"><tt class="xref py py-exc docutils literal"><span class="pre">SyntaxError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_SystemError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.SystemError" title="exceptions.SystemError"><tt class="xref py py-exc docutils literal"><span class="pre">SystemError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_SystemExit</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.SystemExit" title="exceptions.SystemExit"><tt class="xref py py-exc docutils literal"><span class="pre">SystemExit</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_TypeError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.TypeError" title="exceptions.TypeError"><tt class="xref py py-exc docutils literal"><span class="pre">TypeError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_ValueError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_WindowsError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.WindowsError" title="exceptions.WindowsError"><tt class="xref py py-exc docutils literal"><span class="pre">WindowsError</span></tt></a></td>
<td>(3)</td>
</tr>
<tr class="row-even"><td><tt class="xref c c-data docutils literal"><span class="pre">PyExc_ZeroDivisionError</span></tt></td>
<td><a class="reference internal" href="../library/exceptions.html#exceptions.ZeroDivisionError" title="exceptions.ZeroDivisionError"><tt class="xref py py-exc docutils literal"><span class="pre">ZeroDivisionError</span></tt></a></td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p id="index-4">Notes:</p>
<ol class="arabic">
<li><p class="first">This is a base class for other standard exceptions.</p>
</li>
<li><p class="first">This is the same as <a class="reference internal" href="../library/weakref.html#weakref.ReferenceError" title="weakref.ReferenceError"><tt class="xref py py-exc docutils literal"><span class="pre">weakref.ReferenceError</span></tt></a>.</p>
</li>
<li><p class="first">Only defined on Windows; protect code that uses this by testing that the
preprocessor macro <tt class="docutils literal"><span class="pre">MS_WINDOWS</span></tt> is defined.</p>
</li>
<li><p class="first versionadded">
<span class="versionmodified">New in version 2.5.</span></p>
</li>
</ol>
</div>
<div class="section" id="string-exceptions">
<h2>String Exceptions<a class="headerlink" href="#string-exceptions" title="Permalink to this headline">¶</a></h2>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.6: </span>All exceptions to be raised or caught must be derived from <a class="reference internal" href="../library/exceptions.html#exceptions.BaseException" title="exceptions.BaseException"><tt class="xref py py-exc docutils literal"><span class="pre">BaseException</span></tt></a>.
Trying to raise a string exception now raises <a class="reference internal" href="../library/exceptions.html#exceptions.TypeError" title="exceptions.TypeError"><tt class="xref py py-exc docutils literal"><span class="pre">TypeError</span></tt></a>.</p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Exception Handling</a><ul>
<li><a class="reference internal" href="#unicode-exception-objects">Unicode Exception Objects</a></li>
<li><a class="reference internal" href="#recursion-control">Recursion Control</a></li>
<li><a class="reference internal" href="#standard-exceptions">Standard Exceptions</a></li>
<li><a class="reference internal" href="#string-exceptions">String Exceptions</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="refcounting.html"
                        title="previous chapter">Reference Counting</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="utilities.html"
                        title="next chapter">Utilities</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/c-api/exceptions.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="utilities.html" title="Utilities"
             >next</a> |</li>
        <li class="right" >
          <a href="refcounting.html" title="Reference Counting"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="http://www.python.org/">Python</a> &raquo;</li>
        <li>
          <a href="../index.html">Python 2.7.5 documentation</a> &raquo;
        </li>

          <li><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2020, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="http://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Oct 13, 2020.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>

  </body>
</html>

SEA-GHOST - SHELL CODING BY SEA-GHOST