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