Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 1 | #ifndef Py_ERRORS_H |
| 2 | #define Py_ERRORS_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 7 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 8 | /* Error handling definitions */ |
| 9 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 10 | PyAPI_FUNC(void) PyErr_SetNone(PyObject *); |
| 11 | PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *); |
| 12 | PyAPI_FUNC(void) PyErr_SetString(PyObject *, const char *); |
| 13 | PyAPI_FUNC(PyObject *) PyErr_Occurred(void); |
| 14 | PyAPI_FUNC(void) PyErr_Clear(void); |
| 15 | PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **); |
| 16 | PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 17 | |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 18 | /* Error testing and normalization */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 19 | PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *); |
| 20 | PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *); |
| 21 | PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**); |
Barry Warsaw | c0dc92a | 1997-08-22 21:22:58 +0000 | [diff] [blame] | 22 | |
| 23 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 24 | /* Predefined exceptions */ |
Guido van Rossum | 5c600e1 | 1990-10-14 20:00:25 +0000 | [diff] [blame] | 25 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 26 | PyAPI_DATA(PyObject *) PyExc_Exception; |
| 27 | PyAPI_DATA(PyObject *) PyExc_StopIteration; |
| 28 | PyAPI_DATA(PyObject *) PyExc_StandardError; |
| 29 | PyAPI_DATA(PyObject *) PyExc_ArithmeticError; |
| 30 | PyAPI_DATA(PyObject *) PyExc_LookupError; |
Barry Warsaw | 392d827 | 1997-08-29 21:56:07 +0000 | [diff] [blame] | 31 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 32 | PyAPI_DATA(PyObject *) PyExc_AssertionError; |
| 33 | PyAPI_DATA(PyObject *) PyExc_AttributeError; |
| 34 | PyAPI_DATA(PyObject *) PyExc_EOFError; |
| 35 | PyAPI_DATA(PyObject *) PyExc_FloatingPointError; |
| 36 | PyAPI_DATA(PyObject *) PyExc_EnvironmentError; |
| 37 | PyAPI_DATA(PyObject *) PyExc_IOError; |
| 38 | PyAPI_DATA(PyObject *) PyExc_OSError; |
| 39 | PyAPI_DATA(PyObject *) PyExc_ImportError; |
| 40 | PyAPI_DATA(PyObject *) PyExc_IndexError; |
| 41 | PyAPI_DATA(PyObject *) PyExc_KeyError; |
| 42 | PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt; |
| 43 | PyAPI_DATA(PyObject *) PyExc_MemoryError; |
| 44 | PyAPI_DATA(PyObject *) PyExc_NameError; |
| 45 | PyAPI_DATA(PyObject *) PyExc_OverflowError; |
| 46 | PyAPI_DATA(PyObject *) PyExc_RuntimeError; |
| 47 | PyAPI_DATA(PyObject *) PyExc_NotImplementedError; |
| 48 | PyAPI_DATA(PyObject *) PyExc_SyntaxError; |
| 49 | PyAPI_DATA(PyObject *) PyExc_IndentationError; |
| 50 | PyAPI_DATA(PyObject *) PyExc_TabError; |
| 51 | PyAPI_DATA(PyObject *) PyExc_ReferenceError; |
| 52 | PyAPI_DATA(PyObject *) PyExc_SystemError; |
| 53 | PyAPI_DATA(PyObject *) PyExc_SystemExit; |
| 54 | PyAPI_DATA(PyObject *) PyExc_TypeError; |
| 55 | PyAPI_DATA(PyObject *) PyExc_UnboundLocalError; |
| 56 | PyAPI_DATA(PyObject *) PyExc_UnicodeError; |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 57 | PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError; |
| 58 | PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError; |
| 59 | PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError; |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 60 | PyAPI_DATA(PyObject *) PyExc_ValueError; |
| 61 | PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError; |
Guido van Rossum | db0c9f7 | 2000-02-17 15:17:18 +0000 | [diff] [blame] | 62 | #ifdef MS_WINDOWS |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 63 | PyAPI_DATA(PyObject *) PyExc_WindowsError; |
Guido van Rossum | db0c9f7 | 2000-02-17 15:17:18 +0000 | [diff] [blame] | 64 | #endif |
Martin v. Löwis | 79acb9e | 2002-12-06 12:48:53 +0000 | [diff] [blame] | 65 | #ifdef __VMS |
| 66 | extern DL_IMPORT(PyObject *) PyExc_VMSError; |
| 67 | #endif |
Guido van Rossum | 3e55cb6 | 1990-10-21 22:09:30 +0000 | [diff] [blame] | 68 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 69 | PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst; |
Barry Warsaw | 392d827 | 1997-08-29 21:56:07 +0000 | [diff] [blame] | 70 | |
Guido van Rossum | 3fc3037 | 2000-12-15 21:57:34 +0000 | [diff] [blame] | 71 | /* Predefined warning categories */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 72 | PyAPI_DATA(PyObject *) PyExc_Warning; |
| 73 | PyAPI_DATA(PyObject *) PyExc_UserWarning; |
| 74 | PyAPI_DATA(PyObject *) PyExc_DeprecationWarning; |
| 75 | PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning; |
| 76 | PyAPI_DATA(PyObject *) PyExc_SyntaxWarning; |
| 77 | PyAPI_DATA(PyObject *) PyExc_OverflowWarning; |
| 78 | PyAPI_DATA(PyObject *) PyExc_RuntimeWarning; |
Barry Warsaw | 9f00739 | 2002-08-14 15:51:29 +0000 | [diff] [blame] | 79 | PyAPI_DATA(PyObject *) PyExc_FutureWarning; |
Guido van Rossum | 3fc3037 | 2000-12-15 21:57:34 +0000 | [diff] [blame] | 80 | |
Barry Warsaw | 392d827 | 1997-08-29 21:56:07 +0000 | [diff] [blame] | 81 | |
Guido van Rossum | 5c600e1 | 1990-10-14 20:00:25 +0000 | [diff] [blame] | 82 | /* Convenience functions */ |
| 83 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 84 | PyAPI_FUNC(int) PyErr_BadArgument(void); |
| 85 | PyAPI_FUNC(PyObject *) PyErr_NoMemory(void); |
| 86 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 87 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject( |
| 88 | PyObject *, PyObject *); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 89 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(PyObject *, char *); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 90 | #ifdef Py_WIN_WIDE_FILENAMES |
| 91 | PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename( |
| 92 | PyObject *, Py_UNICODE *); |
| 93 | #endif /* Py_WIN_WIDE_FILENAMES */ |
| 94 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 95 | PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...) |
Neil Schemenauer | 96aa0ac | 2002-09-15 14:09:54 +0000 | [diff] [blame] | 96 | Py_GCC_ATTRIBUTE((format(printf, 2, 3))); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 97 | |
Guido van Rossum | db0c9f7 | 2000-02-17 15:17:18 +0000 | [diff] [blame] | 98 | #ifdef MS_WINDOWS |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 99 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject( |
| 100 | int, const char *); |
| 101 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename( |
| 102 | int, const char *); |
| 103 | #ifdef Py_WIN_WIDE_FILENAMES |
| 104 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename( |
| 105 | int, const Py_UNICODE *); |
| 106 | #endif /* Py_WIN_WIDE_FILENAMES */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 107 | PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 108 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject( |
| 109 | PyObject *,int, PyObject *); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 110 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename( |
Thomas Heller | 085358a | 2002-07-29 14:27:41 +0000 | [diff] [blame] | 111 | PyObject *,int, const char *); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 112 | #ifdef Py_WIN_WIDE_FILENAMES |
| 113 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename( |
| 114 | PyObject *,int, const Py_UNICODE *); |
| 115 | #endif /* Py_WIN_WIDE_FILENAMES */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 116 | PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int); |
Mark Hammond | c2e85bd | 2002-10-03 05:10:39 +0000 | [diff] [blame] | 117 | #endif /* MS_WINDOWS */ |
Guido van Rossum | 3e55cb6 | 1990-10-21 22:09:30 +0000 | [diff] [blame] | 118 | |
Fred Drake | 6d63adf | 2000-08-24 22:38:39 +0000 | [diff] [blame] | 119 | /* Export the old function so that the existing API remains available: */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 120 | PyAPI_FUNC(void) PyErr_BadInternalCall(void); |
| 121 | PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename, int lineno); |
Fred Drake | 6d63adf | 2000-08-24 22:38:39 +0000 | [diff] [blame] | 122 | /* 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 Rossum | 2583165 | 1993-05-19 14:50:45 +0000 | [diff] [blame] | 125 | |
Guido van Rossum | 2d2c344 | 1997-09-16 21:50:37 +0000 | [diff] [blame] | 126 | /* Function to create a new exception */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 127 | PyAPI_FUNC(PyObject *) PyErr_NewException(char *name, PyObject *base, |
Fred Drake | d5c84ed | 2000-07-08 17:25:55 +0000 | [diff] [blame] | 128 | PyObject *dict); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 129 | PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *); |
Guido van Rossum | 2d2c344 | 1997-09-16 21:50:37 +0000 | [diff] [blame] | 130 | |
Guido van Rossum | 3fc3037 | 2000-12-15 21:57:34 +0000 | [diff] [blame] | 131 | /* Issue a warning or exception */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 132 | PyAPI_FUNC(int) PyErr_Warn(PyObject *, char *); |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 133 | PyAPI_FUNC(int) PyErr_WarnExplicit(PyObject *, const char *, |
| 134 | const char *, int, |
| 135 | const char *, PyObject *); |
Guido van Rossum | 3fc3037 | 2000-12-15 21:57:34 +0000 | [diff] [blame] | 136 | |
Barry Warsaw | f3f41a9 | 1997-01-03 00:15:03 +0000 | [diff] [blame] | 137 | /* In sigcheck.c or signalmodule.c */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 138 | PyAPI_FUNC(int) PyErr_CheckSignals(void); |
| 139 | PyAPI_FUNC(void) PyErr_SetInterrupt(void); |
Jeremy Hylton | ad3d3f2 | 2001-02-28 17:47:12 +0000 | [diff] [blame] | 140 | |
| 141 | /* Support for adding program text to SyntaxErrors */ |
Martin v. Löwis | 95292d6 | 2002-12-11 14:04:59 +0000 | [diff] [blame] | 142 | PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int); |
| 143 | PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int); |
Tim Peters | a437d45 | 2001-11-28 16:51:49 +0000 | [diff] [blame] | 144 | |
Walter Dörwald | bf73db8 | 2002-11-21 20:08:33 +0000 | [diff] [blame] | 145 | #ifdef Py_USING_UNICODE |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 146 | /* The following functions are used to create and modify unicode |
| 147 | exceptions from C */ |
Walter Dörwald | bf73db8 | 2002-11-21 20:08:33 +0000 | [diff] [blame] | 148 | |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 149 | /* create a UnicodeDecodeError object */ |
| 150 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create( |
| 151 | const char *, const char *, int, int, int, const char *); |
| 152 | |
| 153 | /* create a UnicodeEncodeError object */ |
| 154 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create( |
| 155 | const char *, const Py_UNICODE *, int, int, int, const char *); |
| 156 | |
| 157 | /* create a UnicodeTranslateError object */ |
| 158 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create( |
| 159 | const Py_UNICODE *, int, int, int, const char *); |
| 160 | |
| 161 | /* get the encoding attribute */ |
| 162 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *); |
| 163 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *); |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 164 | |
| 165 | /* get the object attribute */ |
| 166 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *); |
| 167 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *); |
| 168 | PyAPI_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 */ |
| 172 | PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, int *); |
| 173 | PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, int *); |
| 174 | PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, int *); |
| 175 | |
| 176 | /* assign a new value to the start attribute |
| 177 | return 0 on success, -1 on failure */ |
| 178 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, int); |
| 179 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, int); |
| 180 | PyAPI_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 */ |
| 184 | PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, int *); |
| 185 | PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, int *); |
| 186 | PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, int *); |
| 187 | |
| 188 | /* assign a new value to the end attribute |
| 189 | return 0 on success, -1 on failure */ |
| 190 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, int); |
| 191 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, int); |
| 192 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, int); |
| 193 | |
| 194 | /* get the value of the reason attribute */ |
| 195 | PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *); |
| 196 | PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *); |
| 197 | PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *); |
| 198 | |
| 199 | /* assign a new value to the reason attribute |
| 200 | return 0 on success, -1 on failure */ |
| 201 | PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason( |
| 202 | PyObject *, const char *); |
| 203 | PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason( |
| 204 | PyObject *, const char *); |
| 205 | PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason( |
| 206 | PyObject *, const char *); |
Walter Dörwald | bf73db8 | 2002-11-21 20:08:33 +0000 | [diff] [blame] | 207 | #endif |
Walter Dörwald | 3aeb632 | 2002-09-02 13:14:32 +0000 | [diff] [blame] | 208 | |
| 209 | |
Marc-André Lemburg | e5006eb | 2001-07-31 13:24:44 +0000 | [diff] [blame] | 210 | /* 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 Peters | a437d45 | 2001-11-28 16:51:49 +0000 | [diff] [blame] | 213 | 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é Lemburg | e5006eb | 2001-07-31 13:24:44 +0000 | [diff] [blame] | 218 | #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF) |
| 219 | # define HAVE_SNPRINTF |
| 220 | # define snprintf _snprintf |
| 221 | # define vsnprintf _vsnprintf |
| 222 | #endif |
Marc-André Lemburg | 03d1b18 | 2001-07-31 18:05:33 +0000 | [diff] [blame] | 223 | |
Marc-André Lemburg | cecd9e0 | 2001-07-31 14:23:52 +0000 | [diff] [blame] | 224 | #include <stdarg.h> |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 225 | PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...) |
Neil Schemenauer | 96aa0ac | 2002-09-15 14:09:54 +0000 | [diff] [blame] | 226 | Py_GCC_ATTRIBUTE((format(printf, 3, 4))); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 227 | PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va) |
Neil Schemenauer | 96aa0ac | 2002-09-15 14:09:54 +0000 | [diff] [blame] | 228 | Py_GCC_ATTRIBUTE((format(printf, 3, 0))); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 229 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 230 | #ifdef __cplusplus |
| 231 | } |
| 232 | #endif |
| 233 | #endif /* !Py_ERRORS_H */ |