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