1#ifndef Py_CPYTHON_ERRORS_H 2# error "this header file must not be included directly" 3#endif 4 5/* Error objects */ 6 7/* PyException_HEAD defines the initial segment of every exception class. */ 8#define PyException_HEAD PyObject_HEAD PyObject *dict;\ 9 PyObject *args; PyObject *notes; PyObject *traceback;\ 10 PyObject *context; PyObject *cause;\ 11 char suppress_context; 12 13typedef struct { 14 PyException_HEAD 15} PyBaseExceptionObject; 16 17typedef struct { 18 PyException_HEAD 19 PyObject *msg; 20 PyObject *excs; 21} PyBaseExceptionGroupObject; 22 23typedef struct { 24 PyException_HEAD 25 PyObject *msg; 26 PyObject *filename; 27 PyObject *lineno; 28 PyObject *offset; 29 PyObject *end_lineno; 30 PyObject *end_offset; 31 PyObject *text; 32 PyObject *print_file_and_line; 33} PySyntaxErrorObject; 34 35typedef struct { 36 PyException_HEAD 37 PyObject *msg; 38 PyObject *name; 39 PyObject *path; 40} PyImportErrorObject; 41 42typedef struct { 43 PyException_HEAD 44 PyObject *encoding; 45 PyObject *object; 46 Py_ssize_t start; 47 Py_ssize_t end; 48 PyObject *reason; 49} PyUnicodeErrorObject; 50 51typedef struct { 52 PyException_HEAD 53 PyObject *code; 54} PySystemExitObject; 55 56typedef struct { 57 PyException_HEAD 58 PyObject *myerrno; 59 PyObject *strerror; 60 PyObject *filename; 61 PyObject *filename2; 62#ifdef MS_WINDOWS 63 PyObject *winerror; 64#endif 65 Py_ssize_t written; /* only for BlockingIOError, -1 otherwise */ 66} PyOSErrorObject; 67 68typedef struct { 69 PyException_HEAD 70 PyObject *value; 71} PyStopIterationObject; 72 73typedef struct { 74 PyException_HEAD 75 PyObject *name; 76} PyNameErrorObject; 77 78typedef struct { 79 PyException_HEAD 80 PyObject *obj; 81 PyObject *name; 82} PyAttributeErrorObject; 83 84/* Compatibility typedefs */ 85typedef PyOSErrorObject PyEnvironmentErrorObject; 86#ifdef MS_WINDOWS 87typedef PyOSErrorObject PyWindowsErrorObject; 88#endif 89 90/* Error handling definitions */ 91 92PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *); 93PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate); 94PyAPI_FUNC(PyObject*) _PyErr_GetHandledException(PyThreadState *); 95PyAPI_FUNC(void) _PyErr_SetHandledException(PyThreadState *, PyObject *); 96PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **); 97 98/* Context manipulation (PEP 3134) */ 99 100PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *); 101 102/* Like PyErr_Format(), but saves current exception as __context__ and 103 __cause__. 104 */ 105PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause( 106 PyObject *exception, 107 const char *format, /* ASCII-encoded string */ 108 ... 109 ); 110 111/* In exceptions.c */ 112 113/* Helper that attempts to replace the current exception with one of the 114 * same type but with a prefix added to the exception text. The resulting 115 * exception description looks like: 116 * 117 * prefix (exc_type: original_exc_str) 118 * 119 * Only some exceptions can be safely replaced. If the function determines 120 * it isn't safe to perform the replacement, it will leave the original 121 * unmodified exception in place. 122 * 123 * Returns a borrowed reference to the new exception (if any), NULL if the 124 * existing exception was left in place. 125 */ 126PyAPI_FUNC(PyObject *) _PyErr_TrySetFromCause( 127 const char *prefix_format, /* ASCII-encoded string */ 128 ... 129 ); 130 131/* In signalmodule.c */ 132 133int PySignal_SetWakeupFd(int fd); 134PyAPI_FUNC(int) _PyErr_CheckSignals(void); 135 136/* Support for adding program text to SyntaxErrors */ 137 138PyAPI_FUNC(void) PyErr_SyntaxLocationObject( 139 PyObject *filename, 140 int lineno, 141 int col_offset); 142 143PyAPI_FUNC(void) PyErr_RangedSyntaxLocationObject( 144 PyObject *filename, 145 int lineno, 146 int col_offset, 147 int end_lineno, 148 int end_col_offset); 149 150PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject( 151 PyObject *filename, 152 int lineno); 153 154PyAPI_FUNC(PyObject *) _PyErr_ProgramDecodedTextObject( 155 PyObject *filename, 156 int lineno, 157 const char* encoding); 158 159PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create( 160 PyObject *object, 161 Py_ssize_t start, 162 Py_ssize_t end, 163 const char *reason /* UTF-8 encoded string */ 164 ); 165 166PyAPI_FUNC(void) _PyErr_WriteUnraisableMsg( 167 const char *err_msg, 168 PyObject *obj); 169 170PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFunc( 171 const char *func, 172 const char *message); 173 174PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat( 175 const char *func, 176 const char *format, 177 ...); 178 179#define Py_FatalError(message) _Py_FatalErrorFunc(__func__, message) 180