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(
189 PyObject
*, const char *);
191 PyAPI_FUNC(PyObject
*) PyErr_SetFromErrnoWithUnicodeFilename(
192 PyObject
*, const Py_UNICODE
*);
193 #endif /* MS_WINDOWS */
195 PyAPI_FUNC(PyObject
*) PyErr_Format(PyObject
*, const char *, ...)
196 Py_GCC_ATTRIBUTE((format(printf
, 2, 3)));
199 PyAPI_FUNC(PyObject
*) PyErr_SetFromWindowsErrWithFilenameObject(
201 PyAPI_FUNC(PyObject
*) PyErr_SetFromWindowsErrWithFilename(
203 PyAPI_FUNC(PyObject
*) PyErr_SetFromWindowsErrWithUnicodeFilename(
204 int, const Py_UNICODE
*);
205 PyAPI_FUNC(PyObject
*) PyErr_SetFromWindowsErr(int);
206 PyAPI_FUNC(PyObject
*) PyErr_SetExcFromWindowsErrWithFilenameObject(
207 PyObject
*,int, PyObject
*);
208 PyAPI_FUNC(PyObject
*) PyErr_SetExcFromWindowsErrWithFilename(
209 PyObject
*,int, const char *);
210 PyAPI_FUNC(PyObject
*) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
211 PyObject
*,int, const Py_UNICODE
*);
212 PyAPI_FUNC(PyObject
*) PyErr_SetExcFromWindowsErr(PyObject
*, int);
213 #endif /* MS_WINDOWS */
215 /* Export the old function so that the existing API remains available: */
216 PyAPI_FUNC(void) PyErr_BadInternalCall(void);
217 PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename
, int lineno
);
218 /* Mask the old API with a call to the new API for code compiled under
220 #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
222 /* Function to create a new exception */
223 PyAPI_FUNC(PyObject
*) PyErr_NewException(char *name
, PyObject
*base
,
225 PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject
*);
227 /* In sigcheck.c or signalmodule.c */
228 PyAPI_FUNC(int) PyErr_CheckSignals(void);
229 PyAPI_FUNC(void) PyErr_SetInterrupt(void);
231 /* In signalmodule.c */
232 int PySignal_SetWakeupFd(int fd
);
234 /* Support for adding program text to SyntaxErrors */
235 PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
236 PyAPI_FUNC(PyObject
*) PyErr_ProgramText(const char *, int);
238 #ifdef Py_USING_UNICODE
239 /* The following functions are used to create and modify unicode
242 /* create a UnicodeDecodeError object */
243 PyAPI_FUNC(PyObject
*) PyUnicodeDecodeError_Create(
244 const char *, const char *, Py_ssize_t
, Py_ssize_t
, Py_ssize_t
, const char *);
246 /* create a UnicodeEncodeError object */
247 PyAPI_FUNC(PyObject
*) PyUnicodeEncodeError_Create(
248 const char *, const Py_UNICODE
*, Py_ssize_t
, Py_ssize_t
, Py_ssize_t
, const char *);
250 /* create a UnicodeTranslateError object */
251 PyAPI_FUNC(PyObject
*) PyUnicodeTranslateError_Create(
252 const Py_UNICODE
*, Py_ssize_t
, Py_ssize_t
, Py_ssize_t
, const char *);
254 /* get the encoding attribute */
255 PyAPI_FUNC(PyObject
*) PyUnicodeEncodeError_GetEncoding(PyObject
*);
256 PyAPI_FUNC(PyObject
*) PyUnicodeDecodeError_GetEncoding(PyObject
*);
258 /* get the object attribute */
259 PyAPI_FUNC(PyObject
*) PyUnicodeEncodeError_GetObject(PyObject
*);
260 PyAPI_FUNC(PyObject
*) PyUnicodeDecodeError_GetObject(PyObject
*);
261 PyAPI_FUNC(PyObject
*) PyUnicodeTranslateError_GetObject(PyObject
*);
263 /* get the value of the start attribute (the int * may not be NULL)
264 return 0 on success, -1 on failure */
265 PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject
*, Py_ssize_t
*);
266 PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject
*, Py_ssize_t
*);
267 PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject
*, Py_ssize_t
*);
269 /* assign a new value to the start attribute
270 return 0 on success, -1 on failure */
271 PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject
*, Py_ssize_t
);
272 PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject
*, Py_ssize_t
);
273 PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject
*, Py_ssize_t
);
275 /* get the value of the end attribute (the int *may not be NULL)
276 return 0 on success, -1 on failure */
277 PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject
*, Py_ssize_t
*);
278 PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject
*, Py_ssize_t
*);
279 PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject
*, Py_ssize_t
*);
281 /* assign a new value to the end attribute
282 return 0 on success, -1 on failure */
283 PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject
*, Py_ssize_t
);
284 PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject
*, Py_ssize_t
);
285 PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject
*, Py_ssize_t
);
287 /* get the value of the reason attribute */
288 PyAPI_FUNC(PyObject
*) PyUnicodeEncodeError_GetReason(PyObject
*);
289 PyAPI_FUNC(PyObject
*) PyUnicodeDecodeError_GetReason(PyObject
*);
290 PyAPI_FUNC(PyObject
*) PyUnicodeTranslateError_GetReason(PyObject
*);
292 /* assign a new value to the reason attribute
293 return 0 on success, -1 on failure */
294 PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(
295 PyObject
*, const char *);
296 PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(
297 PyObject
*, const char *);
298 PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
299 PyObject
*, const char *);
303 /* These APIs aren't really part of the error implementation, but
304 often needed to format error messages; the native C lib APIs are
305 not available on all platforms, which is why we provide emulations
306 for those platforms in Python/mysnprintf.c,
307 WARNING: The return value of snprintf varies across platforms; do
308 not rely on any particular behavior; eventually the C99 defn may
311 #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
312 # define HAVE_SNPRINTF
313 # define snprintf _snprintf
314 # define vsnprintf _vsnprintf
318 PyAPI_FUNC(int) PyOS_snprintf(char *str
, size_t size
, const char *format
, ...)
319 Py_GCC_ATTRIBUTE((format(printf
, 3, 4)));
320 PyAPI_FUNC(int) PyOS_vsnprintf(char *str
, size_t size
, const char *format
, va_list va
)
321 Py_GCC_ATTRIBUTE((format(printf
, 3, 0)));
326 #endif /* !Py_ERRORS_H */