blob: 6b0ccedac52dab2c7a400821db2065e455a992fb [file] [log] [blame]
Victor Stinner5a8c2402018-11-26 22:11:25 +01001#ifndef Py_CPYTHON_ERRORS_H
2# error "this header file must not be included directly"
3#endif
4
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9/* Error objects */
10
11/* PyException_HEAD defines the initial segment of every exception class. */
12#define PyException_HEAD PyObject_HEAD PyObject *dict;\
13 PyObject *args; PyObject *traceback;\
14 PyObject *context; PyObject *cause;\
15 char suppress_context;
16
17typedef struct {
18 PyException_HEAD
19} PyBaseExceptionObject;
20
21typedef struct {
22 PyException_HEAD
23 PyObject *msg;
24 PyObject *filename;
25 PyObject *lineno;
26 PyObject *offset;
27 PyObject *text;
28 PyObject *print_file_and_line;
29} PySyntaxErrorObject;
30
31typedef struct {
32 PyException_HEAD
33 PyObject *msg;
34 PyObject *name;
35 PyObject *path;
36} PyImportErrorObject;
37
38typedef struct {
39 PyException_HEAD
40 PyObject *encoding;
41 PyObject *object;
42 Py_ssize_t start;
43 Py_ssize_t end;
44 PyObject *reason;
45} PyUnicodeErrorObject;
46
47typedef struct {
48 PyException_HEAD
49 PyObject *code;
50} PySystemExitObject;
51
52typedef struct {
53 PyException_HEAD
54 PyObject *myerrno;
55 PyObject *strerror;
56 PyObject *filename;
57 PyObject *filename2;
58#ifdef MS_WINDOWS
59 PyObject *winerror;
60#endif
61 Py_ssize_t written; /* only for BlockingIOError, -1 otherwise */
62} PyOSErrorObject;
63
64typedef struct {
65 PyException_HEAD
66 PyObject *value;
67} PyStopIterationObject;
68
69/* Compatibility typedefs */
70typedef PyOSErrorObject PyEnvironmentErrorObject;
71#ifdef MS_WINDOWS
72typedef PyOSErrorObject PyWindowsErrorObject;
73#endif
74
75/* Error handling definitions */
76
77PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *);
78_PyErr_StackItem *_PyErr_GetTopmostException(PyThreadState *tstate);
79
80/* Context manipulation (PEP 3134) */
81
82PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
83
84/* */
85
86#define PyExceptionClass_Name(x) (((PyTypeObject*)(x))->tp_name)
87
88/* Convenience functions */
89
90#ifdef MS_WINDOWS
91PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
92 PyObject *, const Py_UNICODE *) Py_DEPRECATED(3.3);
93#endif /* MS_WINDOWS */
94
95/* Like PyErr_Format(), but saves current exception as __context__ and
96 __cause__.
97 */
98PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
99 PyObject *exception,
100 const char *format, /* ASCII-encoded string */
101 ...
102 );
103
104#ifdef MS_WINDOWS
105/* XXX redeclare to use WSTRING */
106PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
107 int, const Py_UNICODE *) Py_DEPRECATED(3.3);
108
109PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
110 PyObject *,int, const Py_UNICODE *) Py_DEPRECATED(3.3);
111#endif
112
113/* In exceptions.c */
114
115/* Helper that attempts to replace the current exception with one of the
116 * same type but with a prefix added to the exception text. The resulting
117 * exception description looks like:
118 *
119 * prefix (exc_type: original_exc_str)
120 *
121 * Only some exceptions can be safely replaced. If the function determines
122 * it isn't safe to perform the replacement, it will leave the original
123 * unmodified exception in place.
124 *
125 * Returns a borrowed reference to the new exception (if any), NULL if the
126 * existing exception was left in place.
127 */
128PyAPI_FUNC(PyObject *) _PyErr_TrySetFromCause(
129 const char *prefix_format, /* ASCII-encoded string */
130 ...
131 );
132
133/* In signalmodule.c */
134
135int PySignal_SetWakeupFd(int fd);
Eric Snow64d6cc82019-02-23 15:40:43 -0700136PyAPI_FUNC(int) _PyErr_CheckSignals(void);
Victor Stinner5a8c2402018-11-26 22:11:25 +0100137
138/* Support for adding program text to SyntaxErrors */
139
140PyAPI_FUNC(void) PyErr_SyntaxLocationObject(
141 PyObject *filename,
142 int lineno,
143 int col_offset);
144
145PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject(
146 PyObject *filename,
147 int lineno);
148
149/* Create a UnicodeEncodeError object */
150PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
151 const char *encoding, /* UTF-8 encoded string */
152 const Py_UNICODE *object,
153 Py_ssize_t length,
154 Py_ssize_t start,
155 Py_ssize_t end,
156 const char *reason /* UTF-8 encoded string */
157 ) Py_DEPRECATED(3.3);
158
159/* Create a UnicodeTranslateError object */
160PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
161 const Py_UNICODE *object,
162 Py_ssize_t length,
163 Py_ssize_t start,
164 Py_ssize_t end,
165 const char *reason /* UTF-8 encoded string */
166 ) Py_DEPRECATED(3.3);
167PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
168 PyObject *object,
169 Py_ssize_t start,
170 Py_ssize_t end,
171 const char *reason /* UTF-8 encoded string */
172 );
173
Victor Stinner71c52e32019-05-27 08:57:14 +0200174PyAPI_FUNC(void) _PyErr_WriteUnraisableMsg(
175 const char *err_msg,
176 PyObject *obj);
Victor Stinner5a8c2402018-11-26 22:11:25 +0100177
178#ifdef __cplusplus
179}
180#endif