1#ifndef Py_ERRORS_H
2#define Py_ERRORS_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7#include <stdarg.h> // va_list
8
9/* Error handling definitions */
10
11PyAPI_FUNC(void) PyErr_SetNone(PyObject *);
12PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);
13PyAPI_FUNC(void) PyErr_SetString(
14 PyObject *exception,
15 const char *string /* decoded from utf-8 */
16 );
17PyAPI_FUNC(PyObject *) PyErr_Occurred(void);
18PyAPI_FUNC(void) PyErr_Clear(void);
19PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
20PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
21#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
22PyAPI_FUNC(void) PyErr_GetExcInfo(PyObject **, PyObject **, PyObject **);
23PyAPI_FUNC(void) PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *);
24#endif
25
26/* Defined in Python/pylifecycle.c
27
28 The Py_FatalError() function is replaced with a macro which logs
29 automatically the name of the current function, unless the Py_LIMITED_API
30 macro is defined. */
31PyAPI_FUNC(void) _Py_NO_RETURN Py_FatalError(const char *message);
32
33/* Error testing and normalization */
34PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
35PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);
36PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
37
38/* Traceback manipulation (PEP 3134) */
39PyAPI_FUNC(int) PyException_SetTraceback(PyObject *, PyObject *);
40PyAPI_FUNC(PyObject *) PyException_GetTraceback(PyObject *);
41
42/* Cause manipulation (PEP 3134) */
43PyAPI_FUNC(PyObject *) PyException_GetCause(PyObject *);
44PyAPI_FUNC(void) PyException_SetCause(PyObject *, PyObject *);
45
46/* Context manipulation (PEP 3134) */
47PyAPI_FUNC(PyObject *) PyException_GetContext(PyObject *);
48PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *);
49
50/* */
51
52#define PyExceptionClass_Check(x) \
53 (PyType_Check((x)) && \
54 PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
55
56#define PyExceptionInstance_Check(x) \
57 PyType_FastSubclass(Py_TYPE(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)
58
59PyAPI_FUNC(const char *) PyExceptionClass_Name(PyObject *);
60
61#define PyExceptionInstance_Class(x) ((PyObject*)Py_TYPE(x))
62
63
64/* Predefined exceptions */
65
66PyAPI_DATA(PyObject *) PyExc_BaseException;
67PyAPI_DATA(PyObject *) PyExc_Exception;
68#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
69PyAPI_DATA(PyObject *) PyExc_StopAsyncIteration;
70#endif
71PyAPI_DATA(PyObject *) PyExc_StopIteration;
72PyAPI_DATA(PyObject *) PyExc_GeneratorExit;
73PyAPI_DATA(PyObject *) PyExc_ArithmeticError;
74PyAPI_DATA(PyObject *) PyExc_LookupError;
75
76PyAPI_DATA(PyObject *) PyExc_AssertionError;
77PyAPI_DATA(PyObject *) PyExc_AttributeError;
78PyAPI_DATA(PyObject *) PyExc_BufferError;
79PyAPI_DATA(PyObject *) PyExc_EOFError;
80PyAPI_DATA(PyObject *) PyExc_FloatingPointError;
81PyAPI_DATA(PyObject *) PyExc_OSError;
82PyAPI_DATA(PyObject *) PyExc_ImportError;
83#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000
84PyAPI_DATA(PyObject *) PyExc_ModuleNotFoundError;
85#endif
86PyAPI_DATA(PyObject *) PyExc_IndexError;
87PyAPI_DATA(PyObject *) PyExc_KeyError;
88PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt;
89PyAPI_DATA(PyObject *) PyExc_MemoryError;
90PyAPI_DATA(PyObject *) PyExc_NameError;
91PyAPI_DATA(PyObject *) PyExc_OverflowError;
92PyAPI_DATA(PyObject *) PyExc_RuntimeError;
93#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
94PyAPI_DATA(PyObject *) PyExc_RecursionError;
95#endif
96PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
97PyAPI_DATA(PyObject *) PyExc_SyntaxError;
98PyAPI_DATA(PyObject *) PyExc_IndentationError;
99PyAPI_DATA(PyObject *) PyExc_TabError;
100PyAPI_DATA(PyObject *) PyExc_ReferenceError;
101PyAPI_DATA(PyObject *) PyExc_SystemError;
102PyAPI_DATA(PyObject *) PyExc_SystemExit;
103PyAPI_DATA(PyObject *) PyExc_TypeError;
104PyAPI_DATA(PyObject *) PyExc_UnboundLocalError;
105PyAPI_DATA(PyObject *) PyExc_UnicodeError;
106PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError;
107PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError;
108PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError;
109PyAPI_DATA(PyObject *) PyExc_ValueError;
110PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError;
111
112#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
113PyAPI_DATA(PyObject *) PyExc_BlockingIOError;
114PyAPI_DATA(PyObject *) PyExc_BrokenPipeError;
115PyAPI_DATA(PyObject *) PyExc_ChildProcessError;
116PyAPI_DATA(PyObject *) PyExc_ConnectionError;
117PyAPI_DATA(PyObject *) PyExc_ConnectionAbortedError;
118PyAPI_DATA(PyObject *) PyExc_ConnectionRefusedError;
119PyAPI_DATA(PyObject *) PyExc_ConnectionResetError;
120PyAPI_DATA(PyObject *) PyExc_FileExistsError;
121PyAPI_DATA(PyObject *) PyExc_FileNotFoundError;
122PyAPI_DATA(PyObject *) PyExc_InterruptedError;
123PyAPI_DATA(PyObject *) PyExc_IsADirectoryError;
124PyAPI_DATA(PyObject *) PyExc_NotADirectoryError;
125PyAPI_DATA(PyObject *) PyExc_PermissionError;
126PyAPI_DATA(PyObject *) PyExc_ProcessLookupError;
127PyAPI_DATA(PyObject *) PyExc_TimeoutError;
128#endif
129
130
131/* Compatibility aliases */
132PyAPI_DATA(PyObject *) PyExc_EnvironmentError;
133PyAPI_DATA(PyObject *) PyExc_IOError;
134#ifdef MS_WINDOWS
135PyAPI_DATA(PyObject *) PyExc_WindowsError;
136#endif
137
138/* Predefined warning categories */
139PyAPI_DATA(PyObject *) PyExc_Warning;
140PyAPI_DATA(PyObject *) PyExc_UserWarning;
141PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
142PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
143PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
144PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
145PyAPI_DATA(PyObject *) PyExc_FutureWarning;
146PyAPI_DATA(PyObject *) PyExc_ImportWarning;
147PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;
148PyAPI_DATA(PyObject *) PyExc_BytesWarning;
149PyAPI_DATA(PyObject *) PyExc_EncodingWarning;
150PyAPI_DATA(PyObject *) PyExc_ResourceWarning;
151
152
153/* Convenience functions */
154
155PyAPI_FUNC(int) PyErr_BadArgument(void);
156PyAPI_FUNC(PyObject *) PyErr_NoMemory(void);
157PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
158PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(
159 PyObject *, PyObject *);
160#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
161PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObjects(
162 PyObject *, PyObject *, PyObject *);
163#endif
164PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(
165 PyObject *exc,
166 const char *filename /* decoded from the filesystem encoding */
167 );
168
169PyAPI_FUNC(PyObject *) PyErr_Format(
170 PyObject *exception,
171 const char *format, /* ASCII-encoded string */
172 ...
173 );
174#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
175PyAPI_FUNC(PyObject *) PyErr_FormatV(
176 PyObject *exception,
177 const char *format,
178 va_list vargs);
179#endif
180
181#ifdef MS_WINDOWS
182PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
183 int ierr,
184 const char *filename /* decoded from the filesystem encoding */
185 );
186PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
187PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
188 PyObject *,int, PyObject *);
189#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
190PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObjects(
191 PyObject *,int, PyObject *, PyObject *);
192#endif
193PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
194 PyObject *exc,
195 int ierr,
196 const char *filename /* decoded from the filesystem encoding */
197 );
198PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
199#endif /* MS_WINDOWS */
200
201#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000
202PyAPI_FUNC(PyObject *) PyErr_SetImportErrorSubclass(PyObject *, PyObject *,
203 PyObject *, PyObject *);
204#endif
205#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
206PyAPI_FUNC(PyObject *) PyErr_SetImportError(PyObject *, PyObject *,
207 PyObject *);
208#endif
209
210/* Export the old function so that the existing API remains available: */
211PyAPI_FUNC(void) PyErr_BadInternalCall(void);
212PyAPI_FUNC(void) _PyErr_BadInternalCall(const char *filename, int lineno);
213/* Mask the old API with a call to the new API for code compiled under
214 Python 2.0: */
215#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
216
217/* Function to create a new exception */
218PyAPI_FUNC(PyObject *) PyErr_NewException(
219 const char *name, PyObject *base, PyObject *dict);
220PyAPI_FUNC(PyObject *) PyErr_NewExceptionWithDoc(
221 const char *name, const char *doc, PyObject *base, PyObject *dict);
222PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
223
224
225/* In signalmodule.c */
226PyAPI_FUNC(int) PyErr_CheckSignals(void);
227PyAPI_FUNC(void) PyErr_SetInterrupt(void);
228#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
229PyAPI_FUNC(int) PyErr_SetInterruptEx(int signum);
230#endif
231
232/* Support for adding program text to SyntaxErrors */
233PyAPI_FUNC(void) PyErr_SyntaxLocation(
234 const char *filename, /* decoded from the filesystem encoding */
235 int lineno);
236PyAPI_FUNC(void) PyErr_SyntaxLocationEx(
237 const char *filename, /* decoded from the filesystem encoding */
238 int lineno,
239 int col_offset);
240PyAPI_FUNC(PyObject *) PyErr_ProgramText(
241 const char *filename, /* decoded from the filesystem encoding */
242 int lineno);
243
244/* The following functions are used to create and modify unicode
245 exceptions from C */
246
247/* create a UnicodeDecodeError object */
248PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create(
249 const char *encoding, /* UTF-8 encoded string */
250 const char *object,
251 Py_ssize_t length,
252 Py_ssize_t start,
253 Py_ssize_t end,
254 const char *reason /* UTF-8 encoded string */
255 );
256
257/* get the encoding attribute */
258PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *);
259PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *);
260
261/* get the object attribute */
262PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *);
263PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *);
264PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *);
265
266/* get the value of the start attribute (the int * may not be NULL)
267 return 0 on success, -1 on failure */
268PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *);
269PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *);
270PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *);
271
272/* assign a new value to the start attribute
273 return 0 on success, -1 on failure */
274PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t);
275PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t);
276PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t);
277
278/* get the value of the end attribute (the int *may not be NULL)
279 return 0 on success, -1 on failure */
280PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *);
281PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *);
282PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *);
283
284/* assign a new value to the end attribute
285 return 0 on success, -1 on failure */
286PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t);
287PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t);
288PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t);
289
290/* get the value of the reason attribute */
291PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *);
292PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *);
293PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *);
294
295/* assign a new value to the reason attribute
296 return 0 on success, -1 on failure */
297PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(
298 PyObject *exc,
299 const char *reason /* UTF-8 encoded string */
300 );
301PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(
302 PyObject *exc,
303 const char *reason /* UTF-8 encoded string */
304 );
305PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
306 PyObject *exc,
307 const char *reason /* UTF-8 encoded string */
308 );
309
310PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...)
311 Py_GCC_ATTRIBUTE((format(printf, 3, 4)));
312PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
313 Py_GCC_ATTRIBUTE((format(printf, 3, 0)));
314
315#ifndef Py_LIMITED_API
316# define Py_CPYTHON_ERRORS_H
317# include "cpython/pyerrors.h"
318# undef Py_CPYTHON_ERRORS_H
319#endif
320
321#ifdef __cplusplus
322}
323#endif
324#endif /* !Py_ERRORS_H */
325

source code of include/python3.10/pyerrors.h