14 } PyBaseExceptionObject
;
26 PyObject
*print_file_and_line
;
27 } PySyntaxErrorObject
;
29 #ifdef Py_USING_UNICODE
40 } PyUnicodeErrorObject
;
59 } PyEnvironmentErrorObject
;
71 } PyWindowsErrorObject
;
74 /* Error handling definitions */
76 PyAPI_FUNC(void) PyErr_SetNone(PyObject
*);
77 PyAPI_FUNC(void) PyErr_SetObject(PyObject
*, PyObject
*);
78 PyAPI_FUNC(void) PyErr_SetString(PyObject
*, const char *);
79 PyAPI_FUNC(PyObject
*) PyErr_Occurred(void);
80 PyAPI_FUNC(void) PyErr_Clear(void);
81 PyAPI_FUNC(void) PyErr_Fetch(PyObject
**, PyObject
**, PyObject
**);
82 PyAPI_FUNC(void) PyErr_Restore(PyObject
*, PyObject
*, PyObject
*);
85 #define _PyErr_OCCURRED() PyErr_Occurred()
87 #define _PyErr_OCCURRED() (_PyThreadState_Current->curexc_type)
90 /* Error testing and normalization */
91 PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject
*, PyObject
*);
92 PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject
*);
93 PyAPI_FUNC(void) PyErr_NormalizeException(PyObject
**, PyObject
**, PyObject
**);
97 #define PyExceptionClass_Check(x) \
98 (PyClass_Check((x)) || (PyType_Check((x)) && \
99 PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)))
101 #define PyExceptionInstance_Check(x) \
102 (PyInstance_Check((x)) || \
103 PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS))
105 #define PyExceptionClass_Name(x) \
106 (PyClass_Check((x)) \
107 ? PyString_AS_STRING(((PyClassObject*)(x))->cl_name) \
108 : (char *)(((PyTypeObject*)(x))->tp_name))
110 #define PyExceptionInstance_Class(x) \
111 ((PyInstance_Check((x)) \
112 ? (PyObject*)((PyInstanceObject*)(x))->in_class \
113 : (PyObject*)((x)->ob_type)))
116 /* Predefined exceptions */
118 PyAPI_DATA(PyObject
*) PyExc_BaseException
;
119 PyAPI_DATA(PyObject
*) PyExc_Exception
;
120 PyAPI_DATA(PyObject
*) PyExc_StopIteration
;
121 PyAPI_DATA(PyObject
*) PyExc_GeneratorExit
;
122 PyAPI_DATA(PyObject
*) PyExc_StandardError
;
123 PyAPI_DATA(PyObject
*) PyExc_ArithmeticError
;
124 PyAPI_DATA(PyObject
*) PyExc_LookupError
;
126 PyAPI_DATA(PyObject
*) PyExc_AssertionError
;
127 PyAPI_DATA(PyObject
*) PyExc_AttributeError
;
128 PyAPI_DATA(PyObject
*) PyExc_EOFError
;
129 PyAPI_DATA(PyObject
*) PyExc_FloatingPointError
;
130 PyAPI_DATA(PyObject
*) PyExc_EnvironmentError
;
131 PyAPI_DATA(PyObject
*) PyExc_IOError
;
132 PyAPI_DATA(PyObject
*) PyExc_OSError
;
133 PyAPI_DATA(PyObject
*) PyExc_ImportError
;
134 PyAPI_DATA(PyObject
*) PyExc_IndexError
;
135 PyAPI_DATA(PyObject
*) PyExc_KeyError
;
136 PyAPI_DATA(PyObject
*) PyExc_KeyboardInterrupt
;
137 PyAPI_DATA(PyObject
*) PyExc_MemoryError
;
138 PyAPI_DATA(PyObject
*) PyExc_NameError
;
139 PyAPI_DATA(PyObject
*) PyExc_OverflowError
;
140 PyAPI_DATA(PyObject
*) PyExc_RuntimeError
;
141 PyAPI_DATA(PyObject
*) PyExc_NotImplementedError
;
142 PyAPI_DATA(PyObject
*) PyExc_SyntaxError
;
143 PyAPI_DATA(PyObject
*) PyExc_IndentationError
;
144 PyAPI_DATA(PyObject
*) PyExc_TabError
;
145 PyAPI_DATA(PyObject
*) PyExc_ReferenceError
;
146 PyAPI_DATA(PyObject
*) PyExc_SystemError
;
147 PyAPI_DATA(PyObject
*) PyExc_SystemExit
;
148 PyAPI_DATA(PyObject
*) PyExc_TypeError
;
149 PyAPI_DATA(PyObject
*) PyExc_UnboundLocalError
;
150 PyAPI_DATA(PyObject
*) PyExc_UnicodeError
;
151 PyAPI_DATA(PyObject
*) PyExc_UnicodeEncodeError
;
152 PyAPI_DATA(PyObject
*) PyExc_UnicodeDecodeError
;
153 PyAPI_DATA(PyObject
*) PyExc_UnicodeTranslateError
;
154 PyAPI_DATA(PyObject
*) PyExc_ValueError
;
155 PyAPI_DATA(PyObject
*) PyExc_ZeroDivisionError
;
157 PyAPI_DATA(PyObject
*) PyExc_WindowsError
;
160 PyAPI_DATA(PyObject
*) PyExc_VMSError
;
163 PyAPI_DATA(PyObject
*) PyExc_BufferError
;
165 PyAPI_DATA(PyObject
*) PyExc_MemoryErrorInst
;
166 PyAPI_DATA(PyObject
*) PyExc_RecursionErrorInst
;
168 /* Predefined warning categories */
169 PyAPI_DATA(PyObject
*) PyExc_Warning
;
170 PyAPI_DATA(PyObject
*) PyExc_UserWarning
;
171 PyAPI_DATA(PyObject
*) PyExc_DeprecationWarning
;
172 PyAPI_DATA(PyObject
*) PyExc_PendingDeprecationWarning
;
173 PyAPI_DATA(PyObject
*) PyExc_SyntaxWarning
;
174 PyAPI_DATA(PyObject
*) PyExc_RuntimeWarning
;
175 PyAPI_DATA(PyObject
*) PyExc_FutureWarning
;
176 PyAPI_DATA(PyObject
*) PyExc_ImportWarning
;
177 PyAPI_DATA(PyObject
*) PyExc_UnicodeWarning
;
178 PyAPI_DATA(PyObject
*) PyExc_BytesWarning
;
181 /* Convenience functions */
183 PyAPI_FUNC(int) PyErr_BadArgument(void);
184 PyAPI_FUNC(PyObject
*) PyErr_NoMemory(void);
185 PyAPI_FUNC(PyObject
*) PyErr_SetFromErrno(PyObject
*);
186 PyAPI_FUNC(PyObject
*) PyErr_SetFromErrnoWithFilenameObject(
187 PyObject
*, PyObject
*);
188 PyAPI_FUNC(PyObject
*) PyErr_SetFromErrnoWithFilename(PyObject
*, char *);
189 #ifdef Py_WIN_WIDE_FILENAMES
190 PyAPI_FUNC(PyObject
*) PyErr_SetFromErrnoWithUnicodeFilename(
191 PyObject
*, Py_UNICODE
*);
192 #endif /* Py_WIN_WIDE_FILENAMES */
194 PyAPI_FUNC(PyObject
*) PyErr_Format(PyObject
*, const char *, ...)
195 Py_GCC_ATTRIBUTE((format(printf
, 2, 3)));
198 PyAPI_FUNC(PyObject
*) PyErr_SetFromWindowsErrWithFilenameObject(
200 PyAPI_FUNC(PyObject
*) PyErr_SetFromWindowsErrWithFilename(
202 #ifdef Py_WIN_WIDE_FILENAMES
203 PyAPI_FUNC(PyObject
*) PyErr_SetFromWindowsErrWithUnicodeFilename(
204 int, const Py_UNICODE
*);
205 #endif /* Py_WIN_WIDE_FILENAMES */
206 PyAPI_FUNC(PyObject
*) PyErr_SetFromWindowsErr(int);
207 PyAPI_FUNC(PyObject
*) PyErr_SetExcFromWindowsErrWithFilenameObject(
208 PyObject
*,int, PyObject
*);
209 PyAPI_FUNC(PyObject
*) PyErr_SetExcFromWindowsErrWithFilename(
210 PyObject
*,int, const char *);
211 #ifdef Py_WIN_WIDE_FILENAMES
212 PyAPI_FUNC(PyObject
*) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
213 PyObject
*,int, const Py_UNICODE
*);
214 #endif /* Py_WIN_WIDE_FILENAMES */
215 PyAPI_FUNC(PyObject
*) PyErr_SetExcFromWindowsErr(PyObject
*, int);
216 #endif /* MS_WINDOWS */
218 /* Export the old function so that the existing API remains available: */
219 PyAPI_FUNC(void) PyErr_BadInternalCall(void);
220 PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename
, int lineno
);
221 /* Mask the old API with a call to the new API for code compiled under
223 #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
225 /* Function to create a new exception */
226 PyAPI_FUNC(PyObject
*) PyErr_NewException(char *name
, PyObject
*base
,
228 PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject
*);
230 /* In sigcheck.c or signalmodule.c */
231 PyAPI_FUNC(int) PyErr_CheckSignals(void);
232 PyAPI_FUNC(void) PyErr_SetInterrupt(void);
234 /* In signalmodule.c */
235 int PySignal_SetWakeupFd(int fd
);
237 /* Support for adding program text to SyntaxErrors */
238 PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
239 PyAPI_FUNC(PyObject
*) PyErr_ProgramText(const char *, int);
241 #ifdef Py_USING_UNICODE
242 /* The following functions are used to create and modify unicode
245 /* create a UnicodeDecodeError object */
246 PyAPI_FUNC(PyObject
*) PyUnicodeDecodeError_Create(
247 const char *, const char *, Py_ssize_t
, Py_ssize_t
, Py_ssize_t
, const char *);
249 /* create a UnicodeEncodeError object */
250 PyAPI_FUNC(PyObject
*) PyUnicodeEncodeError_Create(
251 const char *, const Py_UNICODE
*, Py_ssize_t
, Py_ssize_t
, Py_ssize_t
, const char *);
253 /* create a UnicodeTranslateError object */
254 PyAPI_FUNC(PyObject
*) PyUnicodeTranslateError_Create(
255 const Py_UNICODE
*, Py_ssize_t
, Py_ssize_t
, Py_ssize_t
, const char *);
257 /* get the encoding attribute */
258 PyAPI_FUNC(PyObject
*) PyUnicodeEncodeError_GetEncoding(PyObject
*);
259 PyAPI_FUNC(PyObject
*) PyUnicodeDecodeError_GetEncoding(PyObject
*);
261 /* get the object attribute */
262 PyAPI_FUNC(PyObject
*) PyUnicodeEncodeError_GetObject(PyObject
*);
263 PyAPI_FUNC(PyObject
*) PyUnicodeDecodeError_GetObject(PyObject
*);
264 PyAPI_FUNC(PyObject
*) PyUnicodeTranslateError_GetObject(PyObject
*);
266 /* get the value of the start attribute (the int * may not be NULL)
267 return 0 on success, -1 on failure */
268 PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject
*, Py_ssize_t
*);
269 PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject
*, Py_ssize_t
*);
270 PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject
*, Py_ssize_t
*);
272 /* assign a new value to the start attribute
273 return 0 on success, -1 on failure */
274 PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject
*, Py_ssize_t
);
275 PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject
*, Py_ssize_t
);
276 PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject
*, Py_ssize_t
);
278 /* get the value of the end attribute (the int *may not be NULL)
279 return 0 on success, -1 on failure */
280 PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject
*, Py_ssize_t
*);
281 PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject
*, Py_ssize_t
*);
282 PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject
*, Py_ssize_t
*);
284 /* assign a new value to the end attribute
285 return 0 on success, -1 on failure */
286 PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject
*, Py_ssize_t
);
287 PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject
*, Py_ssize_t
);
288 PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject
*, Py_ssize_t
);
290 /* get the value of the reason attribute */
291 PyAPI_FUNC(PyObject
*) PyUnicodeEncodeError_GetReason(PyObject
*);
292 PyAPI_FUNC(PyObject
*) PyUnicodeDecodeError_GetReason(PyObject
*);
293 PyAPI_FUNC(PyObject
*) PyUnicodeTranslateError_GetReason(PyObject
*);
295 /* assign a new value to the reason attribute
296 return 0 on success, -1 on failure */
297 PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(
298 PyObject
*, const char *);
299 PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(
300 PyObject
*, const char *);
301 PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
302 PyObject
*, const char *);
306 /* These APIs aren't really part of the error implementation, but
307 often needed to format error messages; the native C lib APIs are
308 not available on all platforms, which is why we provide emulations
309 for those platforms in Python/mysnprintf.c,
310 WARNING: The return value of snprintf varies across platforms; do
311 not rely on any particular behavior; eventually the C99 defn may
314 #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
315 # define HAVE_SNPRINTF
316 # define snprintf _snprintf
317 # define vsnprintf _vsnprintf
321 PyAPI_FUNC(int) PyOS_snprintf(char *str
, size_t size
, const char *format
, ...)
322 Py_GCC_ATTRIBUTE((format(printf
, 3, 4)));
323 PyAPI_FUNC(int) PyOS_vsnprintf(char *str
, size_t size
, const char *format
, va_list va
)
324 Py_GCC_ATTRIBUTE((format(printf
, 3, 0)));
329 #endif /* !Py_ERRORS_H */