annotate Doc/c-api/exceptions.rst @ 78069:a8aa77458e12 3.2

Add c_size_t and c_ssize_t to the ctypes summary table.
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 12 Jul 2012 20:31:50 +0200
parents 9c6f7fe31d8e
children e451c5659d64
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
1 .. highlightlang:: c
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
2
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
3
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
4 .. _exceptionhandling:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
5
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
6 ******************
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
7 Exception Handling
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
8 ******************
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
9
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
10 The functions described in this chapter will let you handle and raise Python
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
11 exceptions. It is important to understand some of the basics of Python
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
12 exception handling. It works somewhat like the Unix :c:data:`errno` variable:
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
13 there is a global indicator (per thread) of the last error that occurred. Most
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
14 functions don't clear this on success, but will set it to indicate the cause of
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
15 the error on failure. Most functions also return an error indicator, usually
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
16 *NULL* if they are supposed to return a pointer, or ``-1`` if they return an
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
17 integer (exception: the :c:func:`PyArg_\*` functions return ``1`` for success and
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
18 ``0`` for failure).
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
19
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
20 When a function must fail because some function it called failed, it generally
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
21 doesn't set the error indicator; the function it called already set it. It is
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
22 responsible for either handling the error and clearing the exception or
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
23 returning after cleaning up any resources it holds (such as object references or
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
24 memory allocations); it should *not* continue normally if it is not prepared to
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
25 handle the error. If returning due to an error, it is important to indicate to
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
26 the caller that an error has been set. If the error is not handled or carefully
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
27 propagated, additional calls into the Python/C API may not behave as intended
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
28 and may fail in mysterious ways.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
29
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
30 The error indicator consists of three Python objects corresponding to the result
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
31 of ``sys.exc_info()``. API functions exist to interact with the error indicator
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
32 in various ways. There is a separate error indicator for each thread.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
33
44396
6556f3f22c19 Merged revisions 59605-59624 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44373
diff changeset
34 .. XXX Order of these should be more thoughtful.
6556f3f22c19 Merged revisions 59605-59624 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44373
diff changeset
35 Either alphabetical or some kind of structure.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
36
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
37
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
38 .. c:function:: void PyErr_PrintEx(int set_sys_last_vars)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
39
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
40 Print a standard traceback to ``sys.stderr`` and clear the error indicator.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
41 Call this function only when the error indicator is set. (Otherwise it will
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
42 cause a fatal error!)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
43
51333
3f277b565f76 #5096: document PyErr_PrintEx().
Georg Brandl <georg@python.org>
parents: 50404
diff changeset
44 If *set_sys_last_vars* is nonzero, the variables :data:`sys.last_type`,
3f277b565f76 #5096: document PyErr_PrintEx().
Georg Brandl <georg@python.org>
parents: 50404
diff changeset
45 :data:`sys.last_value` and :data:`sys.last_traceback` will be set to the
3f277b565f76 #5096: document PyErr_PrintEx().
Georg Brandl <georg@python.org>
parents: 50404
diff changeset
46 type, value and traceback of the printed exception, respectively.
3f277b565f76 #5096: document PyErr_PrintEx().
Georg Brandl <georg@python.org>
parents: 50404
diff changeset
47
3f277b565f76 #5096: document PyErr_PrintEx().
Georg Brandl <georg@python.org>
parents: 50404
diff changeset
48
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
49 .. c:function:: void PyErr_Print()
51333
3f277b565f76 #5096: document PyErr_PrintEx().
Georg Brandl <georg@python.org>
parents: 50404
diff changeset
50
3f277b565f76 #5096: document PyErr_PrintEx().
Georg Brandl <georg@python.org>
parents: 50404
diff changeset
51 Alias for ``PyErr_PrintEx(1)``.
3f277b565f76 #5096: document PyErr_PrintEx().
Georg Brandl <georg@python.org>
parents: 50404
diff changeset
52
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
53
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
54 .. c:function:: PyObject* PyErr_Occurred()
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
55
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
56 Test whether the error indicator is set. If set, return the exception *type*
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
57 (the first argument to the last call to one of the :c:func:`PyErr_Set\*`
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
58 functions or to :c:func:`PyErr_Restore`). If not set, return *NULL*. You do not
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
59 own a reference to the return value, so you do not need to :c:func:`Py_DECREF`
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
60 it.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
61
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
62 .. note::
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
63
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
64 Do not compare the return value to a specific exception; use
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
65 :c:func:`PyErr_ExceptionMatches` instead, shown below. (The comparison could
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
66 easily fail since the exception may be an instance instead of a class, in the
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
67 case of a class exception, or it may the a subclass of the expected exception.)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
68
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
69
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
70 .. c:function:: int PyErr_ExceptionMatches(PyObject *exc)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
71
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
72 Equivalent to ``PyErr_GivenExceptionMatches(PyErr_Occurred(), exc)``. This
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
73 should only be called when an exception is actually set; a memory access
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
74 violation will occur if no exception has been raised.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
75
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
76
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
77 .. c:function:: int PyErr_GivenExceptionMatches(PyObject *given, PyObject *exc)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
78
50404
d32a669f96da Merged revisions 68113 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47266
diff changeset
79 Return true if the *given* exception matches the exception in *exc*. If
d32a669f96da Merged revisions 68113 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47266
diff changeset
80 *exc* is a class object, this also returns true when *given* is an instance
d32a669f96da Merged revisions 68113 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47266
diff changeset
81 of a subclass. If *exc* is a tuple, all exceptions in the tuple (and
d32a669f96da Merged revisions 68113 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47266
diff changeset
82 recursively in subtuples) are searched for a match.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
83
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
84
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
85 .. c:function:: void PyErr_NormalizeException(PyObject**exc, PyObject**val, PyObject**tb)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
86
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
87 Under certain circumstances, the values returned by :c:func:`PyErr_Fetch` below
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
88 can be "unnormalized", meaning that ``*exc`` is a class object but ``*val`` is
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
89 not an instance of the same class. This function can be used to instantiate
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
90 the class in that case. If the values are already normalized, nothing happens.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
91 The delayed normalization is implemented to improve performance.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
92
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
93
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
94 .. c:function:: void PyErr_Clear()
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
95
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
96 Clear the error indicator. If the error indicator is not set, there is no
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
97 effect.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
98
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
99
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
100 .. c:function:: void PyErr_Fetch(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
101
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
102 Retrieve the error indicator into three variables whose addresses are passed.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
103 If the error indicator is not set, set all three variables to *NULL*. If it is
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
104 set, it will be cleared and you own a reference to each object retrieved. The
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
105 value and traceback object may be *NULL* even when the type object is not.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
106
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
107 .. note::
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
108
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
109 This function is normally only used by code that needs to handle exceptions or
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
110 by code that needs to save and restore the error indicator temporarily.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
111
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
112
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
113 .. c:function:: void PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
114
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
115 Set the error indicator from the three objects. If the error indicator is
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
116 already set, it is cleared first. If the objects are *NULL*, the error
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
117 indicator is cleared. Do not pass a *NULL* type and non-*NULL* value or
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
118 traceback. The exception type should be a class. Do not pass an invalid
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
119 exception type or value. (Violating these rules will cause subtle problems
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
120 later.) This call takes away a reference to each object: you must own a
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
121 reference to each object before the call and after the call you no longer own
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
122 these references. (If you don't understand this, don't use this function. I
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
123 warned you.)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
124
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
125 .. note::
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
126
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
127 This function is normally only used by code that needs to save and restore the
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
128 error indicator temporarily; use :c:func:`PyErr_Fetch` to save the current
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
129 exception state.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
130
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
131
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
132 .. c:function:: void PyErr_SetString(PyObject *type, const char *message)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
133
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
134 This is the most common way to set the error indicator. The first argument
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
135 specifies the exception type; it is normally one of the standard exceptions,
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
136 e.g. :c:data:`PyExc_RuntimeError`. You need not increment its reference count.
65190
0c4884db53e0 Issue #9738: Document PyErr_SetString() and PyErr_SetFromErrnoWithFilename()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65137
diff changeset
137 The second argument is an error message; it is decoded from ``'utf-8``'.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
138
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
139
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
140 .. c:function:: void PyErr_SetObject(PyObject *type, PyObject *value)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
141
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
142 This function is similar to :c:func:`PyErr_SetString` but lets you specify an
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
143 arbitrary Python object for the "value" of the exception.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
144
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
145
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
146 .. c:function:: PyObject* PyErr_Format(PyObject *exception, const char *format, ...)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
147
66519
f951274af3c7 Merged revisions 86838 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 66478
diff changeset
148 This function sets the error indicator and returns *NULL*. *exception*
f951274af3c7 Merged revisions 86838 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 66478
diff changeset
149 should be a Python exception class. The *format* and subsequent
f951274af3c7 Merged revisions 86838 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 66478
diff changeset
150 parameters help format the error message; they have the same meaning and
67173
ef93531d0ac4 Issue #9738: Fix typo, ASCII-encoding string => ASCII-encoded string
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67163
diff changeset
151 values as in :c:func:`PyUnicode_FromFormat`. *format* is an ASCII-encoded
67149
93e95b2e1a1a Issue #9738: Document encodings of error and warning functions
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67001
diff changeset
152 string.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
153
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
154
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
155 .. c:function:: void PyErr_SetNone(PyObject *type)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
156
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
157 This is a shorthand for ``PyErr_SetObject(type, Py_None)``.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
158
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
159
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
160 .. c:function:: int PyErr_BadArgument()
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
161
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
162 This is a shorthand for ``PyErr_SetString(PyExc_TypeError, message)``, where
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
163 *message* indicates that a built-in operation was invoked with an illegal
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
164 argument. It is mostly for internal use.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
165
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
166
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
167 .. c:function:: PyObject* PyErr_NoMemory()
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
168
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
169 This is a shorthand for ``PyErr_SetNone(PyExc_MemoryError)``; it returns *NULL*
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
170 so an object allocation function can write ``return PyErr_NoMemory();`` when it
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
171 runs out of memory.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
172
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
173
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
174 .. c:function:: PyObject* PyErr_SetFromErrno(PyObject *type)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
175
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
176 .. index:: single: strerror()
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
177
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
178 This is a convenience function to raise an exception when a C library function
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
179 has returned an error and set the C variable :c:data:`errno`. It constructs a
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
180 tuple object whose first item is the integer :c:data:`errno` value and whose
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
181 second item is the corresponding error message (gotten from :c:func:`strerror`),
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
182 and then calls ``PyErr_SetObject(type, object)``. On Unix, when the
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
183 :c:data:`errno` value is :const:`EINTR`, indicating an interrupted system call,
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
184 this calls :c:func:`PyErr_CheckSignals`, and if that set the error indicator,
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
185 leaves it set to that. The function always returns *NULL*, so a wrapper
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
186 function around a system call can write ``return PyErr_SetFromErrno(type);``
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
187 when the system call returns an error.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
188
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
189
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
190 .. c:function:: PyObject* PyErr_SetFromErrnoWithFilename(PyObject *type, const char *filename)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
191
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
192 Similar to :c:func:`PyErr_SetFromErrno`, with the additional behavior that if
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
193 *filename* is not *NULL*, it is passed to the constructor of *type* as a third
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
194 parameter. In the case of exceptions such as :exc:`IOError` and :exc:`OSError`,
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
195 this is used to define the :attr:`filename` attribute of the exception instance.
65190
0c4884db53e0 Issue #9738: Document PyErr_SetString() and PyErr_SetFromErrnoWithFilename()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65137
diff changeset
196 *filename* is decoded from the filesystem encoding
0c4884db53e0 Issue #9738: Document PyErr_SetString() and PyErr_SetFromErrnoWithFilename()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 65137
diff changeset
197 (:func:`sys.getfilesystemencoding`).
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
198
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
199
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
200 .. c:function:: PyObject* PyErr_SetFromWindowsErr(int ierr)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
201
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
202 This is a convenience function to raise :exc:`WindowsError`. If called with
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
203 *ierr* of :c:data:`0`, the error code returned by a call to :c:func:`GetLastError`
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
204 is used instead. It calls the Win32 function :c:func:`FormatMessage` to retrieve
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
205 the Windows description of error code given by *ierr* or :c:func:`GetLastError`,
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
206 then it constructs a tuple object whose first item is the *ierr* value and whose
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
207 second item is the corresponding error message (gotten from
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
208 :c:func:`FormatMessage`), and then calls ``PyErr_SetObject(PyExc_WindowsError,
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
209 object)``. This function always returns *NULL*. Availability: Windows.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
210
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
211
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
212 .. c:function:: PyObject* PyErr_SetExcFromWindowsErr(PyObject *type, int ierr)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
213
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
214 Similar to :c:func:`PyErr_SetFromWindowsErr`, with an additional parameter
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
215 specifying the exception type to be raised. Availability: Windows.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
216
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
217
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
218 .. c:function:: PyObject* PyErr_SetFromWindowsErrWithFilename(int ierr, const char *filename)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
219
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
220 Similar to :c:func:`PyErr_SetFromWindowsErr`, with the additional behavior that
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
221 if *filename* is not *NULL*, it is passed to the constructor of
67163
5605f6920b63 Issue #10780: PyErr_SetFromWindowsErrWithFilename() and
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67161
diff changeset
222 :exc:`WindowsError` as a third parameter. *filename* is decoded from the
5605f6920b63 Issue #10780: PyErr_SetFromWindowsErrWithFilename() and
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67161
diff changeset
223 filesystem encoding (:func:`sys.getfilesystemencoding`). Availability:
5605f6920b63 Issue #10780: PyErr_SetFromWindowsErrWithFilename() and
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67161
diff changeset
224 Windows.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
225
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
226
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
227 .. c:function:: PyObject* PyErr_SetExcFromWindowsErrWithFilename(PyObject *type, int ierr, char *filename)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
228
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
229 Similar to :c:func:`PyErr_SetFromWindowsErrWithFilename`, with an additional
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
230 parameter specifying the exception type to be raised. Availability: Windows.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
231
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
232
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
233 .. c:function:: void PyErr_SyntaxLocationEx(char *filename, int lineno, int col_offset)
64859
00e4ce31d404 add PyErr_SyntaxLocationEx, to support adding a column offset
Benjamin Peterson <benjamin@python.org>
parents: 64639
diff changeset
234
00e4ce31d404 add PyErr_SyntaxLocationEx, to support adding a column offset
Benjamin Peterson <benjamin@python.org>
parents: 64639
diff changeset
235 Set file, line, and offset information for the current exception. If the
00e4ce31d404 add PyErr_SyntaxLocationEx, to support adding a column offset
Benjamin Peterson <benjamin@python.org>
parents: 64639
diff changeset
236 current exception is not a :exc:`SyntaxError`, then it sets additional
00e4ce31d404 add PyErr_SyntaxLocationEx, to support adding a column offset
Benjamin Peterson <benjamin@python.org>
parents: 64639
diff changeset
237 attributes, which make the exception printing subsystem think the exception
67149
93e95b2e1a1a Issue #9738: Document encodings of error and warning functions
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67001
diff changeset
238 is a :exc:`SyntaxError`. *filename* is decoded from the filesystem encoding
93e95b2e1a1a Issue #9738: Document encodings of error and warning functions
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67001
diff changeset
239 (:func:`sys.getfilesystemencoding`).
64859
00e4ce31d404 add PyErr_SyntaxLocationEx, to support adding a column offset
Benjamin Peterson <benjamin@python.org>
parents: 64639
diff changeset
240
64893
6b9f88ddb4ce note version
Benjamin Peterson <benjamin@python.org>
parents: 64859
diff changeset
241 .. versionadded:: 3.2
6b9f88ddb4ce note version
Benjamin Peterson <benjamin@python.org>
parents: 64859
diff changeset
242
64859
00e4ce31d404 add PyErr_SyntaxLocationEx, to support adding a column offset
Benjamin Peterson <benjamin@python.org>
parents: 64639
diff changeset
243
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
244 .. c:function:: void PyErr_SyntaxLocation(char *filename, int lineno)
64859
00e4ce31d404 add PyErr_SyntaxLocationEx, to support adding a column offset
Benjamin Peterson <benjamin@python.org>
parents: 64639
diff changeset
245
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
246 Like :c:func:`PyErr_SyntaxLocationExc`, but the col_offset parameter is
64859
00e4ce31d404 add PyErr_SyntaxLocationEx, to support adding a column offset
Benjamin Peterson <benjamin@python.org>
parents: 64639
diff changeset
247 omitted.
00e4ce31d404 add PyErr_SyntaxLocationEx, to support adding a column offset
Benjamin Peterson <benjamin@python.org>
parents: 64639
diff changeset
248
00e4ce31d404 add PyErr_SyntaxLocationEx, to support adding a column offset
Benjamin Peterson <benjamin@python.org>
parents: 64639
diff changeset
249
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
250 .. c:function:: void PyErr_BadInternalCall()
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
251
51382
7e28a2b0c1b1 Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 51333
diff changeset
252 This is a shorthand for ``PyErr_SetString(PyExc_SystemError, message)``,
7e28a2b0c1b1 Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 51333
diff changeset
253 where *message* indicates that an internal operation (e.g. a Python/C API
7e28a2b0c1b1 Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 51333
diff changeset
254 function) was invoked with an illegal argument. It is mostly for internal
7e28a2b0c1b1 Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 51333
diff changeset
255 use.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
256
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
257
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
258 .. c:function:: int PyErr_WarnEx(PyObject *category, char *message, int stack_level)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
259
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
260 Issue a warning message. The *category* argument is a warning category (see
67149
93e95b2e1a1a Issue #9738: Document encodings of error and warning functions
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67001
diff changeset
261 below) or *NULL*; the *message* argument is an UTF-8 encoded string. *stack_level* is a
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
262 positive number giving a number of stack frames; the warning will be issued from
63949
fa2d9720a66c Issue #9425: Create PyErr_WarnFormat() function
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59617
diff changeset
263 the currently executing line of code in that stack frame. A *stack_level* of 1
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
264 is the function calling :c:func:`PyErr_WarnEx`, 2 is the function above that,
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
265 and so forth.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
266
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
267 This function normally prints a warning message to *sys.stderr*; however, it is
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
268 also possible that the user has specified that warnings are to be turned into
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
269 errors, and in that case this will raise an exception. It is also possible that
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
270 the function raises an exception because of a problem with the warning machinery
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
271 (the implementation imports the :mod:`warnings` module to do the heavy lifting).
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
272 The return value is ``0`` if no exception is raised, or ``-1`` if an exception
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
273 is raised. (It is not possible to determine whether a warning message is
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
274 actually printed, nor what the reason is for the exception; this is
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
275 intentional.) If an exception is raised, the caller should do its normal
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
276 exception handling (for example, :c:func:`Py_DECREF` owned references and return
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
277 an error value).
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
278
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
279 Warning categories must be subclasses of :c:data:`Warning`; the default warning
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
280 category is :c:data:`RuntimeWarning`. The standard Python warning categories are
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
281 available as global variables whose names are ``PyExc_`` followed by the Python
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
282 exception name. These have the type :c:type:`PyObject\*`; they are all class
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
283 objects. Their names are :c:data:`PyExc_Warning`, :c:data:`PyExc_UserWarning`,
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
284 :c:data:`PyExc_UnicodeWarning`, :c:data:`PyExc_DeprecationWarning`,
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
285 :c:data:`PyExc_SyntaxWarning`, :c:data:`PyExc_RuntimeWarning`, and
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
286 :c:data:`PyExc_FutureWarning`. :c:data:`PyExc_Warning` is a subclass of
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
287 :c:data:`PyExc_Exception`; the other warning categories are subclasses of
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
288 :c:data:`PyExc_Warning`.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
289
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
290 For information about warning control, see the documentation for the
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
291 :mod:`warnings` module and the :option:`-W` option in the command line
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
292 documentation. There is no C API for warning control.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
293
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
294
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
295 .. c:function:: int PyErr_WarnExplicit(PyObject *category, const char *message, const char *filename, int lineno, const char *module, PyObject *registry)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
296
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
297 Issue a warning message with explicit control over all warning attributes. This
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
298 is a straightforward wrapper around the Python function
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
299 :func:`warnings.warn_explicit`, see there for more information. The *module*
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
300 and *registry* arguments may be set to *NULL* to get the default effect
67161
6f19622dd342 Issue #10779: PyErr_WarnExplicit() decodes the filename from the filesystem
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67149
diff changeset
301 described there. *message* and *module* are UTF-8 encoded strings,
6f19622dd342 Issue #10779: PyErr_WarnExplicit() decodes the filename from the filesystem
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67149
diff changeset
302 *filename* is decoded from the filesystem encoding
6f19622dd342 Issue #10779: PyErr_WarnExplicit() decodes the filename from the filesystem
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67149
diff changeset
303 (:func:`sys.getfilesystemencoding`).
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
304
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
305
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
306 .. c:function:: int PyErr_WarnFormat(PyObject *category, Py_ssize_t stack_level, const char *format, ...)
63949
fa2d9720a66c Issue #9425: Create PyErr_WarnFormat() function
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59617
diff changeset
307
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
308 Function similar to :c:func:`PyErr_WarnEx`, but use
67149
93e95b2e1a1a Issue #9738: Document encodings of error and warning functions
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67001
diff changeset
309 :c:func:`PyUnicode_FromFormat` to format the warning message. *format* is
93e95b2e1a1a Issue #9738: Document encodings of error and warning functions
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67001
diff changeset
310 an ASCII-encoded string.
63949
fa2d9720a66c Issue #9425: Create PyErr_WarnFormat() function
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59617
diff changeset
311
fa2d9720a66c Issue #9425: Create PyErr_WarnFormat() function
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59617
diff changeset
312 .. versionadded:: 3.2
fa2d9720a66c Issue #9425: Create PyErr_WarnFormat() function
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59617
diff changeset
313
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
314 .. c:function:: int PyErr_CheckSignals()
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
315
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
316 .. index::
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
317 module: signal
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
318 single: SIGINT
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
319 single: KeyboardInterrupt (built-in exception)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
320
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
321 This function interacts with Python's signal handling. It checks whether a
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
322 signal has been sent to the processes and if so, invokes the corresponding
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
323 signal handler. If the :mod:`signal` module is supported, this can invoke a
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
324 signal handler written in Python. In all cases, the default effect for
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
325 :const:`SIGINT` is to raise the :exc:`KeyboardInterrupt` exception. If an
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
326 exception is raised the error indicator is set and the function returns ``-1``;
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
327 otherwise the function returns ``0``. The error indicator may or may not be
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
328 cleared if it was previously set.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
329
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
330
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
331 .. c:function:: void PyErr_SetInterrupt()
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
332
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
333 .. index::
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
334 single: SIGINT
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
335 single: KeyboardInterrupt (built-in exception)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
336
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
337 This function simulates the effect of a :const:`SIGINT` signal arriving --- the
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
338 next time :c:func:`PyErr_CheckSignals` is called, :exc:`KeyboardInterrupt` will
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
339 be raised. It may be called without holding the interpreter lock.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
340
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
341 .. % XXX This was described as obsolete, but is used in
47266
7fe3a8648ce2 Rename thread to _thread and dummy_thread to _dummy_thread. Issue #2875.
Georg Brandl <georg@python.org>
parents: 46963
diff changeset
342 .. % _thread.interrupt_main() (used from IDLE), so it's still needed.
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
343
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
344
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
345 .. c:function:: int PySignal_SetWakeupFd(int fd)
44373
2750d531fdc0 Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43174
diff changeset
346
2750d531fdc0 Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43174
diff changeset
347 This utility function specifies a file descriptor to which a ``'\0'`` byte will
2750d531fdc0 Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43174
diff changeset
348 be written whenever a signal is received. It returns the previous such file
2750d531fdc0 Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43174
diff changeset
349 descriptor. The value ``-1`` disables the feature; this is the initial state.
2750d531fdc0 Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43174
diff changeset
350 This is equivalent to :func:`signal.set_wakeup_fd` in Python, but without any
2750d531fdc0 Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43174
diff changeset
351 error checking. *fd* should be a valid file descriptor. The function should
2750d531fdc0 Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43174
diff changeset
352 only be called from the main thread.
2750d531fdc0 Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43174
diff changeset
353
2750d531fdc0 Merged revisions 59565-59594 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43174
diff changeset
354
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
355 .. c:function:: PyObject* PyErr_NewException(char *name, PyObject *base, PyObject *dict)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
356
71304
9c6f7fe31d8e Clarify that PyErr_NewException creates an exception *class*, not instance.
Georg Brandl <georg@python.org>
parents: 68257
diff changeset
357 This utility function creates and returns a new exception class. The *name*
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
358 argument must be the name of the new exception, a C string of the form
71304
9c6f7fe31d8e Clarify that PyErr_NewException creates an exception *class*, not instance.
Georg Brandl <georg@python.org>
parents: 68257
diff changeset
359 ``module.classname``. The *base* and *dict* arguments are normally *NULL*.
9c6f7fe31d8e Clarify that PyErr_NewException creates an exception *class*, not instance.
Georg Brandl <georg@python.org>
parents: 68257
diff changeset
360 This creates a class object derived from :exc:`Exception` (accessible in C as
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
361 :c:data:`PyExc_Exception`).
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
362
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
363 The :attr:`__module__` attribute of the new class is set to the first part (up
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
364 to the last dot) of the *name* argument, and the class name is set to the last
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
365 part (after the last dot). The *base* argument can be used to specify alternate
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
366 base classes; it can either be only one class or a tuple of classes. The *dict*
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
367 argument can be used to specify a dictionary of class variables and methods.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
368
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
369
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
370 .. c:function:: PyObject* PyErr_NewExceptionWithDoc(char *name, char *doc, PyObject *base, PyObject *dict)
57962
c1972eef3579 Merged revisions 77088 via svnmerge from
Georg Brandl <georg@python.org>
parents: 57295
diff changeset
371
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
372 Same as :c:func:`PyErr_NewException`, except that the new exception class can
57962
c1972eef3579 Merged revisions 77088 via svnmerge from
Georg Brandl <georg@python.org>
parents: 57295
diff changeset
373 easily be given a docstring: If *doc* is non-*NULL*, it will be used as the
c1972eef3579 Merged revisions 77088 via svnmerge from
Georg Brandl <georg@python.org>
parents: 57295
diff changeset
374 docstring for the exception class.
c1972eef3579 Merged revisions 77088 via svnmerge from
Georg Brandl <georg@python.org>
parents: 57295
diff changeset
375
c1972eef3579 Merged revisions 77088 via svnmerge from
Georg Brandl <georg@python.org>
parents: 57295
diff changeset
376 .. versionadded:: 3.2
c1972eef3579 Merged revisions 77088 via svnmerge from
Georg Brandl <georg@python.org>
parents: 57295
diff changeset
377
c1972eef3579 Merged revisions 77088 via svnmerge from
Georg Brandl <georg@python.org>
parents: 57295
diff changeset
378
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
379 .. c:function:: void PyErr_WriteUnraisable(PyObject *obj)
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
380
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
381 This utility function prints a warning message to ``sys.stderr`` when an
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
382 exception has been set but it is impossible for the interpreter to actually
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
383 raise the exception. It is used, for example, when an exception occurs in an
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
384 :meth:`__del__` method.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
385
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
386 The function is called with a single argument *obj* that identifies the context
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
387 in which the unraisable exception occurred. The repr of *obj* will be printed in
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
388 the warning message.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
389
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
390
52509
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
391 Exception Objects
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
392 =================
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
393
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
394 .. c:function:: PyObject* PyException_GetTraceback(PyObject *ex)
52509
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
395
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
396 Return the traceback associated with the exception as a new reference, as
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
397 accessible from Python through :attr:`__traceback__`. If there is no
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
398 traceback associated, this returns *NULL*.
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
399
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
400
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
401 .. c:function:: int PyException_SetTraceback(PyObject *ex, PyObject *tb)
52509
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
402
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
403 Set the traceback associated with the exception to *tb*. Use ``Py_None`` to
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
404 clear it.
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
405
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
406
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
407 .. c:function:: PyObject* PyException_GetContext(PyObject *ex)
52509
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
408
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
409 Return the context (another exception instance during whose handling *ex* was
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
410 raised) associated with the exception as a new reference, as accessible from
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
411 Python through :attr:`__context__`. If there is no context associated, this
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
412 returns *NULL*.
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
413
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
414
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
415 .. c:function:: void PyException_SetContext(PyObject *ex, PyObject *ctx)
52509
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
416
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
417 Set the context associated with the exception to *ctx*. Use *NULL* to clear
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
418 it. There is no type check to make sure that *ctx* is an exception instance.
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
419 This steals a reference to *ctx*.
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
420
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
421
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
422 .. c:function:: PyObject* PyException_GetCause(PyObject *ex)
52509
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
423
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
424 Return the cause (another exception instance set by ``raise ... from ...``)
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
425 associated with the exception as a new reference, as accessible from Python
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
426 through :attr:`__cause__`. If there is no cause associated, this returns
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
427 *NULL*.
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
428
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
429
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
430 .. c:function:: void PyException_SetCause(PyObject *ex, PyObject *ctx)
52509
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
431
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
432 Set the cause associated with the exception to *ctx*. Use *NULL* to clear
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
433 it. There is no type check to make sure that *ctx* is an exception instance.
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
434 This steals a reference to *ctx*.
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
435
d12b02abe6dc Fix segfaults when running test_exceptions with coverage tracing, caused by wrongly defining Exception.__context__ as a T_OBJECT structmember which does not set the member to NULL on None assignment, and generally does not do type checks. This could be used to crash the interpreter by setting any object to __context__. The same applies to __cause__. Also document the PyException_* functions.
Georg Brandl <georg@python.org>
parents: 51382
diff changeset
436
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
437 .. _unicodeexceptions:
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
438
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
439 Unicode Exception Objects
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
440 =========================
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
441
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
442 The following functions are used to create and modify Unicode exceptions from C.
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
443
66414
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
444 .. c:function:: PyObject* PyUnicodeDecodeError_Create(const char *encoding, const char *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason)
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
445
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
446 Create a :class:`UnicodeDecodeError` object with the attributes *encoding*,
67149
93e95b2e1a1a Issue #9738: Document encodings of error and warning functions
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67001
diff changeset
447 *object*, *length*, *start*, *end* and *reason*. *encoding* and *reason* are
93e95b2e1a1a Issue #9738: Document encodings of error and warning functions
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67001
diff changeset
448 UTF-8 encoded strings.
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
449
66414
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
450 .. c:function:: PyObject* PyUnicodeEncodeError_Create(const char *encoding, const Py_UNICODE *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason)
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
451
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
452 Create a :class:`UnicodeEncodeError` object with the attributes *encoding*,
67149
93e95b2e1a1a Issue #9738: Document encodings of error and warning functions
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67001
diff changeset
453 *object*, *length*, *start*, *end* and *reason*. *encoding* and *reason* are
93e95b2e1a1a Issue #9738: Document encodings of error and warning functions
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67001
diff changeset
454 UTF-8 encoded strings.
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
455
66414
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
456 .. c:function:: PyObject* PyUnicodeTranslateError_Create(const Py_UNICODE *object, Py_ssize_t length, Py_ssize_t start, Py_ssize_t end, const char *reason)
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
457
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
458 Create a :class:`UnicodeTranslateError` object with the attributes *object*,
67149
93e95b2e1a1a Issue #9738: Document encodings of error and warning functions
Victor Stinner <victor.stinner@haypocalc.com>
parents: 67001
diff changeset
459 *length*, *start*, *end* and *reason*. *reason* is an UTF-8 encoded string.
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
460
66414
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
461 .. c:function:: PyObject* PyUnicodeDecodeError_GetEncoding(PyObject *exc)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
462 PyObject* PyUnicodeEncodeError_GetEncoding(PyObject *exc)
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
463
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
464 Return the *encoding* attribute of the given exception object.
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
465
66414
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
466 .. c:function:: PyObject* PyUnicodeDecodeError_GetObject(PyObject *exc)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
467 PyObject* PyUnicodeEncodeError_GetObject(PyObject *exc)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
468 PyObject* PyUnicodeTranslateError_GetObject(PyObject *exc)
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
469
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
470 Return the *object* attribute of the given exception object.
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
471
66414
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
472 .. c:function:: int PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
473 int PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
474 int PyUnicodeTranslateError_GetStart(PyObject *exc, Py_ssize_t *start)
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
475
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
476 Get the *start* attribute of the given exception object and place it into
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
477 *\*start*. *start* must not be *NULL*. Return ``0`` on success, ``-1`` on
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
478 failure.
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
479
66414
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
480 .. c:function:: int PyUnicodeDecodeError_SetStart(PyObject *exc, Py_ssize_t start)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
481 int PyUnicodeEncodeError_SetStart(PyObject *exc, Py_ssize_t start)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
482 int PyUnicodeTranslateError_SetStart(PyObject *exc, Py_ssize_t start)
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
483
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
484 Set the *start* attribute of the given exception object to *start*. Return
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
485 ``0`` on success, ``-1`` on failure.
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
486
66414
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
487 .. c:function:: int PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
488 int PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
489 int PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *end)
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
490
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
491 Get the *end* attribute of the given exception object and place it into
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
492 *\*end*. *end* must not be *NULL*. Return ``0`` on success, ``-1`` on
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
493 failure.
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
494
66414
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
495 .. c:function:: int PyUnicodeDecodeError_SetEnd(PyObject *exc, Py_ssize_t end)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
496 int PyUnicodeEncodeError_SetEnd(PyObject *exc, Py_ssize_t end)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
497 int PyUnicodeTranslateError_SetEnd(PyObject *exc, Py_ssize_t end)
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
498
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
499 Set the *end* attribute of the given exception object to *end*. Return ``0``
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
500 on success, ``-1`` on failure.
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
501
66414
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
502 .. c:function:: PyObject* PyUnicodeDecodeError_GetReason(PyObject *exc)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
503 PyObject* PyUnicodeEncodeError_GetReason(PyObject *exc)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
504 PyObject* PyUnicodeTranslateError_GetReason(PyObject *exc)
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
505
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
506 Return the *reason* attribute of the given exception object.
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
507
66414
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
508 .. c:function:: int PyUnicodeDecodeError_SetReason(PyObject *exc, const char *reason)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
509 int PyUnicodeEncodeError_SetReason(PyObject *exc, const char *reason)
3303abe29d0b #10468: document Unicode exception creation and access functions.
Georg Brandl <georg@python.org>
parents: 65190
diff changeset
510 int PyUnicodeTranslateError_SetReason(PyObject *exc, const char *reason)
66478
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
511
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
512 Set the *reason* attribute of the given exception object to *reason*. Return
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
513 ``0`` on success, ``-1`` on failure.
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
514
7281937b2d65 Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents: 65111
diff changeset
515
65111
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
516 Recursion Control
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
517 =================
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
518
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
519 These two functions provide a way to perform safe recursive calls at the C
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
520 level, both in the core and in extension modules. They are needed if the
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
521 recursive code does not necessarily invoke Python code (which tracks its
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
522 recursion depth automatically).
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
523
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
524 .. c:function:: int Py_EnterRecursiveCall(char *where)
65111
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
525
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
526 Marks a point where a recursive C-level call is about to be performed.
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
527
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
528 If :const:`USE_STACKCHECK` is defined, this function checks if the the OS
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
529 stack overflowed using :c:func:`PyOS_CheckStack`. In this is the case, it
65111
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
530 sets a :exc:`MemoryError` and returns a nonzero value.
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
531
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
532 The function then checks if the recursion limit is reached. If this is the
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
533 case, a :exc:`RuntimeError` is set and a nonzero value is returned.
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
534 Otherwise, zero is returned.
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
535
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
536 *where* should be a string such as ``" in instance check"`` to be
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
537 concatenated to the :exc:`RuntimeError` message caused by the recursion depth
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
538 limit.
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
539
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
540 .. c:function:: void Py_LeaveRecursiveCall()
59617
e7b5fc8646ab Merged revisions 78760,78771-78773,78802,78922,78952 via svnmerge from
Georg Brandl <georg@python.org>
parents: 59530
diff changeset
541
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
542 Ends a :c:func:`Py_EnterRecursiveCall`. Must be called once for each
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
543 *successful* invocation of :c:func:`Py_EnterRecursiveCall`.
59617
e7b5fc8646ab Merged revisions 78760,78771-78773,78802,78922,78952 via svnmerge from
Georg Brandl <georg@python.org>
parents: 59530
diff changeset
544
66987
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
545 Properly implementing :attr:`tp_repr` for container types requires
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
546 special recursion handling. In addition to protecting the stack,
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
547 :attr:`tp_repr` also needs to track objects to prevent cycles. The
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
548 following two functions facilitate this functionality. Effectively,
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
549 these are the C equivalent to :func:`reprlib.recursive_repr`.
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
550
67001
28717de4c562 Fix typo
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66987
diff changeset
551 .. c:function:: int Py_ReprEnter(PyObject *object)
66987
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
552
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
553 Called at the beginning of the :attr:`tp_repr` implementation to
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
554 detect cycles.
65111
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
555
66987
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
556 If the object has already been processed, the function returns a
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
557 positive integer. In that case the :attr:`tp_repr` implementation
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
558 should return a string object indicating a cycle. As examples,
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
559 :class:`dict` objects return ``{...}`` and :class:`list` objects
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
560 return ``[...]``.
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
561
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
562 The function will return a negative integer if the recursion limit
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
563 is reached. In that case the :attr:`tp_repr` implementation should
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
564 typically return ``NULL``.
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
565
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
566 Otherwise, the function returns zero and the :attr:`tp_repr`
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
567 implementation can continue normally.
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
568
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
569 .. c:function:: void Py_ReprLeave(PyObject *object)
016b425f0cd0 Issue 8753: Added documentation for Py_ReprEntr and Py_ReprLeave.
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66517
diff changeset
570
67001
28717de4c562 Fix typo
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66987
diff changeset
571 Ends a :c:func:`Py_ReprEnter`. Must be called once for each
28717de4c562 Fix typo
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents: 66987
diff changeset
572 invocation of :c:func:`Py_ReprEnter` that returns zero.
65111
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
573
a4c9746cb03c Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52509
diff changeset
574
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
575 .. _standardexceptions:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
576
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
577 Standard Exceptions
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
578 ===================
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
579
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
580 All standard Python exceptions are available as global variables whose names are
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
581 ``PyExc_`` followed by the Python exception name. These have the type
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
582 :c:type:`PyObject\*`; they are all class objects. For completeness, here are all
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
583 the variables:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
584
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
585 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
586 | C Name | Python Name | Notes |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
587 +=====================================+============================+==========+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
588 | :c:data:`PyExc_BaseException` | :exc:`BaseException` | \(1) |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
589 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
590 | :c:data:`PyExc_Exception` | :exc:`Exception` | \(1) |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
591 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
592 | :c:data:`PyExc_ArithmeticError` | :exc:`ArithmeticError` | \(1) |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
593 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
594 | :c:data:`PyExc_LookupError` | :exc:`LookupError` | \(1) |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
595 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
596 | :c:data:`PyExc_AssertionError` | :exc:`AssertionError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
597 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
598 | :c:data:`PyExc_AttributeError` | :exc:`AttributeError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
599 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
600 | :c:data:`PyExc_EOFError` | :exc:`EOFError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
601 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
602 | :c:data:`PyExc_EnvironmentError` | :exc:`EnvironmentError` | \(1) |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
603 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
604 | :c:data:`PyExc_FloatingPointError` | :exc:`FloatingPointError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
605 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
606 | :c:data:`PyExc_IOError` | :exc:`IOError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
607 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
608 | :c:data:`PyExc_ImportError` | :exc:`ImportError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
609 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
610 | :c:data:`PyExc_IndexError` | :exc:`IndexError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
611 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
612 | :c:data:`PyExc_KeyError` | :exc:`KeyError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
613 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
614 | :c:data:`PyExc_KeyboardInterrupt` | :exc:`KeyboardInterrupt` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
615 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
616 | :c:data:`PyExc_MemoryError` | :exc:`MemoryError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
617 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
618 | :c:data:`PyExc_NameError` | :exc:`NameError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
619 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
620 | :c:data:`PyExc_NotImplementedError` | :exc:`NotImplementedError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
621 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
622 | :c:data:`PyExc_OSError` | :exc:`OSError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
623 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
624 | :c:data:`PyExc_OverflowError` | :exc:`OverflowError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
625 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
626 | :c:data:`PyExc_ReferenceError` | :exc:`ReferenceError` | \(2) |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
627 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
628 | :c:data:`PyExc_RuntimeError` | :exc:`RuntimeError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
629 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
630 | :c:data:`PyExc_SyntaxError` | :exc:`SyntaxError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
631 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
632 | :c:data:`PyExc_SystemError` | :exc:`SystemError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
633 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
634 | :c:data:`PyExc_SystemExit` | :exc:`SystemExit` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
635 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
636 | :c:data:`PyExc_TypeError` | :exc:`TypeError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
637 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
638 | :c:data:`PyExc_ValueError` | :exc:`ValueError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
639 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
640 | :c:data:`PyExc_WindowsError` | :exc:`WindowsError` | \(3) |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
641 +-------------------------------------+----------------------------+----------+
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
642 | :c:data:`PyExc_ZeroDivisionError` | :exc:`ZeroDivisionError` | |
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64893
diff changeset
643 +-------------------------------------+----------------------------+----------+
42604
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
644
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
645 .. index::
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
646 single: PyExc_BaseException
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
647 single: PyExc_Exception
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
648 single: PyExc_ArithmeticError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
649 single: PyExc_LookupError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
650 single: PyExc_AssertionError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
651 single: PyExc_AttributeError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
652 single: PyExc_EOFError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
653 single: PyExc_EnvironmentError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
654 single: PyExc_FloatingPointError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
655 single: PyExc_IOError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
656 single: PyExc_ImportError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
657 single: PyExc_IndexError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
658 single: PyExc_KeyError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
659 single: PyExc_KeyboardInterrupt
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
660 single: PyExc_MemoryError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
661 single: PyExc_NameError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
662 single: PyExc_NotImplementedError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
663 single: PyExc_OSError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
664 single: PyExc_OverflowError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
665 single: PyExc_ReferenceError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
666 single: PyExc_RuntimeError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
667 single: PyExc_SyntaxError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
668 single: PyExc_SystemError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
669 single: PyExc_SystemExit
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
670 single: PyExc_TypeError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
671 single: PyExc_ValueError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
672 single: PyExc_WindowsError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
673 single: PyExc_ZeroDivisionError
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
674
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
675 Notes:
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
676
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
677 (1)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
678 This is a base class for other standard exceptions.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
679
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
680 (2)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
681 This is the same as :exc:`weakref.ReferenceError`.
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
682
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
683 (3)
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
684 Only defined on Windows; protect code that uses this by testing that the
9e1529bf0442 Move the 3k reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
685 preprocessor macro ``MS_WINDOWS`` is defined.