blob: a4ab62ab7c7576a663327d8515a69246a1b32d65 [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_ERRORS_H
2#define Py_ERRORS_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossumf70e43a1991-02-19 12:39:46 +00007
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00008/* Error handling definitions */
9
Mark Hammond91a681d2002-08-12 07:21:58 +000010PyAPI_FUNC(void) PyErr_SetNone(PyObject *);
11PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);
12PyAPI_FUNC(void) PyErr_SetString(PyObject *, const char *);
13PyAPI_FUNC(PyObject *) PyErr_Occurred(void);
14PyAPI_FUNC(void) PyErr_Clear(void);
15PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
16PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000017
Barry Warsawc0dc92a1997-08-22 21:22:58 +000018/* Error testing and normalization */
Mark Hammond91a681d2002-08-12 07:21:58 +000019PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
20PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);
21PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
Barry Warsawc0dc92a1997-08-22 21:22:58 +000022
23
Guido van Rossum3f5da241990-12-20 15:06:42 +000024/* Predefined exceptions */
Guido van Rossum5c600e11990-10-14 20:00:25 +000025
Mark Hammond91a681d2002-08-12 07:21:58 +000026PyAPI_DATA(PyObject *) PyExc_Exception;
27PyAPI_DATA(PyObject *) PyExc_StopIteration;
28PyAPI_DATA(PyObject *) PyExc_StandardError;
29PyAPI_DATA(PyObject *) PyExc_ArithmeticError;
30PyAPI_DATA(PyObject *) PyExc_LookupError;
Barry Warsaw392d8271997-08-29 21:56:07 +000031
Mark Hammond91a681d2002-08-12 07:21:58 +000032PyAPI_DATA(PyObject *) PyExc_AssertionError;
33PyAPI_DATA(PyObject *) PyExc_AttributeError;
34PyAPI_DATA(PyObject *) PyExc_EOFError;
35PyAPI_DATA(PyObject *) PyExc_FloatingPointError;
36PyAPI_DATA(PyObject *) PyExc_EnvironmentError;
37PyAPI_DATA(PyObject *) PyExc_IOError;
38PyAPI_DATA(PyObject *) PyExc_OSError;
39PyAPI_DATA(PyObject *) PyExc_ImportError;
40PyAPI_DATA(PyObject *) PyExc_IndexError;
41PyAPI_DATA(PyObject *) PyExc_KeyError;
42PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt;
43PyAPI_DATA(PyObject *) PyExc_MemoryError;
44PyAPI_DATA(PyObject *) PyExc_NameError;
45PyAPI_DATA(PyObject *) PyExc_OverflowError;
46PyAPI_DATA(PyObject *) PyExc_RuntimeError;
47PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
48PyAPI_DATA(PyObject *) PyExc_SyntaxError;
49PyAPI_DATA(PyObject *) PyExc_IndentationError;
50PyAPI_DATA(PyObject *) PyExc_TabError;
51PyAPI_DATA(PyObject *) PyExc_ReferenceError;
52PyAPI_DATA(PyObject *) PyExc_SystemError;
53PyAPI_DATA(PyObject *) PyExc_SystemExit;
54PyAPI_DATA(PyObject *) PyExc_TypeError;
55PyAPI_DATA(PyObject *) PyExc_UnboundLocalError;
56PyAPI_DATA(PyObject *) PyExc_UnicodeError;
Walter Dörwald3aeb6322002-09-02 13:14:32 +000057PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError;
58PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError;
59PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError;
Mark Hammond91a681d2002-08-12 07:21:58 +000060PyAPI_DATA(PyObject *) PyExc_ValueError;
61PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError;
Guido van Rossumdb0c9f72000-02-17 15:17:18 +000062#ifdef MS_WINDOWS
Mark Hammond91a681d2002-08-12 07:21:58 +000063PyAPI_DATA(PyObject *) PyExc_WindowsError;
Guido van Rossumdb0c9f72000-02-17 15:17:18 +000064#endif
Martin v. Löwis79acb9e2002-12-06 12:48:53 +000065#ifdef __VMS
66extern DL_IMPORT(PyObject *) PyExc_VMSError;
67#endif
Guido van Rossum3e55cb61990-10-21 22:09:30 +000068
Mark Hammond91a681d2002-08-12 07:21:58 +000069PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst;
Barry Warsaw392d8271997-08-29 21:56:07 +000070
Guido van Rossum3fc30372000-12-15 21:57:34 +000071/* Predefined warning categories */
Mark Hammond91a681d2002-08-12 07:21:58 +000072PyAPI_DATA(PyObject *) PyExc_Warning;
73PyAPI_DATA(PyObject *) PyExc_UserWarning;
74PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
75PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
76PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
77PyAPI_DATA(PyObject *) PyExc_OverflowWarning;
78PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
Barry Warsaw9f007392002-08-14 15:51:29 +000079PyAPI_DATA(PyObject *) PyExc_FutureWarning;
Guido van Rossum3fc30372000-12-15 21:57:34 +000080
Barry Warsaw392d8271997-08-29 21:56:07 +000081
Guido van Rossum5c600e11990-10-14 20:00:25 +000082/* Convenience functions */
83
Mark Hammond91a681d2002-08-12 07:21:58 +000084PyAPI_FUNC(int) PyErr_BadArgument(void);
85PyAPI_FUNC(PyObject *) PyErr_NoMemory(void);
86PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
Mark Hammondc2e85bd2002-10-03 05:10:39 +000087PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(
88 PyObject *, PyObject *);
Mark Hammond91a681d2002-08-12 07:21:58 +000089PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(PyObject *, char *);
Mark Hammondc2e85bd2002-10-03 05:10:39 +000090#ifdef Py_WIN_WIDE_FILENAMES
91PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
92 PyObject *, Py_UNICODE *);
93#endif /* Py_WIN_WIDE_FILENAMES */
94
Mark Hammond91a681d2002-08-12 07:21:58 +000095PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...)
Neil Schemenauer96aa0ac2002-09-15 14:09:54 +000096 Py_GCC_ATTRIBUTE((format(printf, 2, 3)));
Mark Hammondc2e85bd2002-10-03 05:10:39 +000097
Guido van Rossumdb0c9f72000-02-17 15:17:18 +000098#ifdef MS_WINDOWS
Mark Hammondc2e85bd2002-10-03 05:10:39 +000099PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject(
100 int, const char *);
101PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
102 int, const char *);
103#ifdef Py_WIN_WIDE_FILENAMES
104PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
105 int, const Py_UNICODE *);
106#endif /* Py_WIN_WIDE_FILENAMES */
Mark Hammond91a681d2002-08-12 07:21:58 +0000107PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
Mark Hammondc2e85bd2002-10-03 05:10:39 +0000108PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
109 PyObject *,int, PyObject *);
Mark Hammond91a681d2002-08-12 07:21:58 +0000110PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
Thomas Heller085358a2002-07-29 14:27:41 +0000111 PyObject *,int, const char *);
Mark Hammondc2e85bd2002-10-03 05:10:39 +0000112#ifdef Py_WIN_WIDE_FILENAMES
113PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
114 PyObject *,int, const Py_UNICODE *);
115#endif /* Py_WIN_WIDE_FILENAMES */
Mark Hammond91a681d2002-08-12 07:21:58 +0000116PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
Mark Hammondc2e85bd2002-10-03 05:10:39 +0000117#endif /* MS_WINDOWS */
Guido van Rossum3e55cb61990-10-21 22:09:30 +0000118
Fred Drake6d63adf2000-08-24 22:38:39 +0000119/* Export the old function so that the existing API remains available: */
Mark Hammond91a681d2002-08-12 07:21:58 +0000120PyAPI_FUNC(void) PyErr_BadInternalCall(void);
121PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename, int lineno);
Fred Drake6d63adf2000-08-24 22:38:39 +0000122/* Mask the old API with a call to the new API for code compiled under
123 Python 2.0: */
124#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
Guido van Rossum25831651993-05-19 14:50:45 +0000125
Guido van Rossum2d2c3441997-09-16 21:50:37 +0000126/* Function to create a new exception */
Mark Hammond91a681d2002-08-12 07:21:58 +0000127PyAPI_FUNC(PyObject *) PyErr_NewException(char *name, PyObject *base,
Fred Draked5c84ed2000-07-08 17:25:55 +0000128 PyObject *dict);
Mark Hammond91a681d2002-08-12 07:21:58 +0000129PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
Guido van Rossum2d2c3441997-09-16 21:50:37 +0000130
Guido van Rossum3fc30372000-12-15 21:57:34 +0000131/* Issue a warning or exception */
Mark Hammond91a681d2002-08-12 07:21:58 +0000132PyAPI_FUNC(int) PyErr_Warn(PyObject *, char *);
Martin v. Löwis95292d62002-12-11 14:04:59 +0000133PyAPI_FUNC(int) PyErr_WarnExplicit(PyObject *, const char *,
134 const char *, int,
135 const char *, PyObject *);
Guido van Rossum3fc30372000-12-15 21:57:34 +0000136
Barry Warsawf3f41a91997-01-03 00:15:03 +0000137/* In sigcheck.c or signalmodule.c */
Mark Hammond91a681d2002-08-12 07:21:58 +0000138PyAPI_FUNC(int) PyErr_CheckSignals(void);
139PyAPI_FUNC(void) PyErr_SetInterrupt(void);
Jeremy Hyltonad3d3f22001-02-28 17:47:12 +0000140
141/* Support for adding program text to SyntaxErrors */
Martin v. Löwis95292d62002-12-11 14:04:59 +0000142PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
143PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);
Tim Petersa437d452001-11-28 16:51:49 +0000144
Walter Dörwaldbf73db82002-11-21 20:08:33 +0000145#ifdef Py_USING_UNICODE
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000146/* The following functions are used to create and modify unicode
147 exceptions from C */
Walter Dörwaldbf73db82002-11-21 20:08:33 +0000148
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000149/* create a UnicodeDecodeError object */
150PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create(
151 const char *, const char *, int, int, int, const char *);
152
153/* create a UnicodeEncodeError object */
154PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
155 const char *, const Py_UNICODE *, int, int, int, const char *);
156
157/* create a UnicodeTranslateError object */
158PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
159 const Py_UNICODE *, int, int, int, const char *);
160
161/* get the encoding attribute */
162PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *);
163PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *);
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000164
165/* get the object attribute */
166PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *);
167PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *);
168PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *);
169
170/* get the value of the start attribute (the int * may not be NULL)
171 return 0 on success, -1 on failure */
172PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, int *);
173PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, int *);
174PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, int *);
175
176/* assign a new value to the start attribute
177 return 0 on success, -1 on failure */
178PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, int);
179PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, int);
180PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, int);
181
182/* get the value of the end attribute (the int *may not be NULL)
183 return 0 on success, -1 on failure */
184PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, int *);
185PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, int *);
186PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, int *);
187
188/* assign a new value to the end attribute
189 return 0 on success, -1 on failure */
190PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, int);
191PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, int);
192PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, int);
193
194/* get the value of the reason attribute */
195PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *);
196PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *);
197PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *);
198
199/* assign a new value to the reason attribute
200 return 0 on success, -1 on failure */
201PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(
202 PyObject *, const char *);
203PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(
204 PyObject *, const char *);
205PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
206 PyObject *, const char *);
Walter Dörwaldbf73db82002-11-21 20:08:33 +0000207#endif
Walter Dörwald3aeb6322002-09-02 13:14:32 +0000208
209
Marc-André Lemburge5006eb2001-07-31 13:24:44 +0000210/* These APIs aren't really part of the error implementation, but
211 often needed to format error messages; the native C lib APIs are
212 not available on all platforms, which is why we provide emulations
Tim Petersa437d452001-11-28 16:51:49 +0000213 for those platforms in Python/mysnprintf.c,
214 WARNING: The return value of snprintf varies across platforms; do
215 not rely on any particular behavior; eventually the C99 defn may
216 be reliable.
217*/
Marc-André Lemburge5006eb2001-07-31 13:24:44 +0000218#if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
219# define HAVE_SNPRINTF
220# define snprintf _snprintf
221# define vsnprintf _vsnprintf
222#endif
Marc-André Lemburg03d1b182001-07-31 18:05:33 +0000223
Marc-André Lemburgcecd9e02001-07-31 14:23:52 +0000224#include <stdarg.h>
Mark Hammond91a681d2002-08-12 07:21:58 +0000225PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...)
Neil Schemenauer96aa0ac2002-09-15 14:09:54 +0000226 Py_GCC_ATTRIBUTE((format(printf, 3, 4)));
Mark Hammond91a681d2002-08-12 07:21:58 +0000227PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
Neil Schemenauer96aa0ac2002-09-15 14:09:54 +0000228 Py_GCC_ATTRIBUTE((format(printf, 3, 0)));
Guido van Rossumb6775db1994-08-01 11:34:53 +0000229
Guido van Rossuma3309961993-07-28 09:05:47 +0000230#ifdef __cplusplus
231}
232#endif
233#endif /* !Py_ERRORS_H */