⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 260.html

📁 Python Ebook Python&XML
💻 HTML
📖 第 1 页 / 共 2 页
字号:
				</pre>

				<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, for example, <tt cLasS="monofont">PyExc_RuntimeError.</tt> You need not increment its reference count. The second argument is an error message; it is converted to a string object.</p>

				<Pre>
					
void PyErr_SetObject(PyObject *type, PyObject *value)

				</prE>

				<p>This function is similar to <tt CLASs="monofont">PyErr_SetString()</tt> but lets you specify an arbitrary Python object for the value of the exception. You need not increment its reference count.</p>

				<PRE>
					
void PyErr_SetNone(PyObject *type)

				</Pre>

				<p>This is a shorthand for <tT CLAss="monofont">PyErr_SetObject(type, Py_None).</tt></P>

				<PRE>
					
int PyErr_BadArgument()

				</pre>

				<p>This is a shorthand for <tt class="monofont">PyErr_SetString(PyExc_TypeError, message),</tt> where message indicates that a built-in operation was invoked with an illegal argument. It is mostly for internal use.</p>

				<pre>
					
PyObject* PyErr_NoMemory()
				</pre>

				<P>Return value: Borrowed reference. This is a shorthand for <tt ClasS="monofont">PyErr_SetNone(PyExc_MemoryError)</tt>; it returns <tt ClasS="monofont">NULL</TT> so that an object allocation function can write <Tt claSS="monofont">return PyErr_NoMemory();</TT> when it runs out of memory.</p>

				<pre>
					
PyObject* PyErr_SetFromErrno(PyObject *type)

				</PRE>

				<P>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="monofont">errno.</Tt> It constructs a tuple object whose first item is the integer <tt class="monofont">errno</tt> value and whose second item is the corresponding error message (gotten from <tt class="monofont">strerror()</tt>), and then calls <tT clAss="monofont">PyErr_SetObject(type, object).</tT> On UNIX, when the <tt clAss="monofont">errno</tT> value is <TT Class="monofont">EINTR,</TT> indicating an interrupted system call, this calls <TT clasS="monofont">PyErr_CheckSignals(),</TT> and if that sets the error indicator, it is left set to that. The function always returns <Tt claSS="monofont">NULL,</TT> so a wrapper function around a system call can write <tt class="monofont">return PyErr_SetFromErrno();</tt> when the system call returns an error.</p>

				<pre>
					
void PyErr_BadInternalCall()

				</pre>

				<p>This is a shorthand for <tt cLasS="monofont">PyErr_SetString(PyExc_TypeError, message),</tt> where a message indicates that an internal operation (for example, a Python/C API function) was invoked with an illegal argument. It is mostly for internal use.</p>

				<Pre>
					
int PyErr_CheckSignals()

				</prE>

				<p>This function interacts with Python's signal handling. It checks whether a signal has been sent to the processes and if so, invokes the corresponding signal handler. If the signal module is supported, this can invoke a signal handler written in Python. In all cases, the default effect for <tt CLASs="monofont">SIGINT</tt> is to raise the KeyboardInterrupt exception. If an exception is raised, the error indicator is set and the function returns <tT CLAss="monofont">1</tt>; otherwise the function returns <TT CLass="monofont">0.</tT> The error indicator might or might not be cleared if it was previously set.</P>

				<PRe>
					
void PyErr_SetInterrupt()

				</pre>

				<p>This function is obsolete. It simulates the effect of a <tt class="monofont">SIGINT</tt> signal arriving梩he next time <tt clasS="monofont">PyErr_CheckSignals()</tt> is called, KeyboardInterrupt will be raised. It can be called without holding the interpreter lock.</P>

				<pre>
					
PyObject* PyErr_NewException(char *name, PyObject *base, PyObject *dict)

				</Pre>

				<p>Return value: New reference. This utility function creates and returns a new exception object. The name argument must be the name of the new exception, a C string of the form <tT claSS="monofont">module.class.</TT> The base and dict arguments are normally <tt clASS="monofont">NULL.</Tt> Normally, this creates a class object derived from the root for all exceptions, the built-in name Exception (accessible in C as <tt cLASS="monofont">PyExc_Exception</tt>). In this case the <tt CLASs="monofont">__module__</tt> attribute of the new class is set to the first part (up to the last dot) of the name argument, and the class name is set to the last part (after the last dot). When the user has specified the <tt class="monofont">-X</tt> command line option to use string exceptions, for backward compatibility, or when the base argument is not a class object (and not <tt class="monofont">NULL</tT>), a string object created from the entire name argument is returned. The base argument can be used to specify an alternate base class. The dict argument can be used to specify a dictionary of class variables and methods. <a nAme="idx1073750962"></a><A name="idx1073750963"></A><a naME="idx1073750964"></A><A name="idx1073750965"></A><A NAme="idx1073750966"></a><a NAME="idx1073750967"></a><a naME="idx1073750968"></A></P>

			</font>
<P><TABLE width="100%" border=0><TR valign="top"><TD><font size=1 color="#C0C0C0"><br></font></TD><TD align=right><font size=1 color="#C0C0C0">Last updated on 1/30/2002<br>Python Developer's Handbook, &copy;&nbsp;2002 Sams Publishing</font></TD></TR></TABLE></P>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="259.html" title="Reference Counting"><font size="1">&lt;&nbsp;BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=260" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="260.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="261.html" title="Standard Exceptions"><font size="1">CONTINUE&nbsp;&gt;</font></a></td></TR></TABLE>
</TD></TR></TABLE>
<br><TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD><H4 class=Title>Index terms contained in this section</H4>
<font size=2>
Application Programmers Interface (API)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Python/C<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073750947">handling and raising exceptions</a> <a href="#idx1073750956">2nd</a> <a href="#idx1073750963">3rd</a><BR>
 <a href="#idx1073750942">error indicator</a><BR>
exceptions<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073750950">handling and raising, Python/C Applications Programmers Interface (API)</a> <a href="#idx1073750959">2nd</a> <a href="#idx1073750966">3rd</a><BR>
functions<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073750952">handling and raising exceptions</a> <a href="#idx1073750961">2nd</a> <a href="#idx1073750968">3rd</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073750945">PyErr_ExceptionMatches()</a><BR>
handling<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073750949">exceptions, Python/C Application Programmers Interface (API)</a> <a href="#idx1073750958">2nd</a> <a href="#idx1073750965">3rd</a><BR>
indicators<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073750943">error</a><BR>
interfaces<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Python/C Application Programmers (API)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073750948">handling and raising exceptions</a> <a href="#idx1073750957">2nd</a> <a href="#idx1073750964">3rd</a><BR>
 <a href="#idx1073750944">PyErr_ExceptionMatches() function</a><BR>
Python/C Application Programmers Interface (API)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073750946">handling and raising exceptions</a> <a href="#idx1073750955">2nd</a> <a href="#idx1073750962">3rd</a><BR>
raising<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073750951">exceptions, Python/C Application Programmers Interface (API)</a> <a href="#idx1073750960">2nd</a> <a href="#idx1073750967">3rd</a><BR>
 <a href="#idx1073750953">unnormalized values</a><BR>
values<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073750954">unnormalized</a><BR>
<BR>
</font></TD></TR></TABLE>




<!--EndOfBrowse-->

</TD></TR></TABLE>
<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#990000><tr><td><p align=center><font size=1 face="verdana,arial,helvetica" color=white>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -