| 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 | |
| 13 | typedef struct { |
| 14 | PyException_HEAD |
| 15 | } PyBaseExceptionObject; |
| 16 | |
| 17 | typedef struct { |
| 18 | PyException_HEAD |
| 19 | PyObject *msg; |
| 20 | PyObject *excs; |
| 21 | } PyBaseExceptionGroupObject; |
| 22 | |
| 23 | typedef 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 | |
| 35 | typedef struct { |
| 36 | PyException_HEAD |
| 37 | PyObject *msg; |
| 38 | PyObject *name; |
| 39 | PyObject *path; |
| 40 | PyObject *name_from; |
| 41 | } PyImportErrorObject; |
| 42 | |
| 43 | typedef struct { |
| 44 | PyException_HEAD |
| 45 | PyObject *encoding; |
| 46 | PyObject *object; |
| 47 | Py_ssize_t start; |
| 48 | Py_ssize_t end; |
| 49 | PyObject *reason; |
| 50 | } PyUnicodeErrorObject; |
| 51 | |
| 52 | typedef struct { |
| 53 | PyException_HEAD |
| 54 | PyObject *code; |
| 55 | } PySystemExitObject; |
| 56 | |
| 57 | typedef struct { |
| 58 | PyException_HEAD |
| 59 | PyObject *myerrno; |
| 60 | PyObject *strerror; |
| 61 | PyObject *filename; |
| 62 | PyObject *filename2; |
| 63 | #ifdef MS_WINDOWS |
| 64 | PyObject *winerror; |
| 65 | #endif |
| 66 | Py_ssize_t written; /* only for BlockingIOError, -1 otherwise */ |
| 67 | } PyOSErrorObject; |
| 68 | |
| 69 | typedef struct { |
| 70 | PyException_HEAD |
| 71 | PyObject *value; |
| 72 | } PyStopIterationObject; |
| 73 | |
| 74 | typedef struct { |
| 75 | PyException_HEAD |
| 76 | PyObject *name; |
| 77 | } PyNameErrorObject; |
| 78 | |
| 79 | typedef struct { |
| 80 | PyException_HEAD |
| 81 | PyObject *obj; |
| 82 | PyObject *name; |
| 83 | } PyAttributeErrorObject; |
| 84 | |
| 85 | /* Compatibility typedefs */ |
| 86 | typedef PyOSErrorObject PyEnvironmentErrorObject; |
| 87 | #ifdef MS_WINDOWS |
| 88 | typedef PyOSErrorObject PyWindowsErrorObject; |
| 89 | #endif |
| 90 | |
| 91 | /* Error handling definitions */ |
| 92 | |
| 93 | PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *); |
| 94 | PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate); |
| 95 | PyAPI_FUNC(PyObject*) _PyErr_GetHandledException(PyThreadState *); |
| 96 | PyAPI_FUNC(void) _PyErr_SetHandledException(PyThreadState *, PyObject *); |
| 97 | PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **); |
| 98 | |
| 99 | /* Context manipulation (PEP 3134) */ |
| 100 | |
| 101 | Py_DEPRECATED(3.12) PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *); |
| 102 | PyAPI_FUNC(void) _PyErr_ChainExceptions1(PyObject *); |
| 103 | |
| 104 | /* Like PyErr_Format(), but saves current exception as __context__ and |
| 105 | __cause__. |
| 106 | */ |
| 107 | PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause( |
| 108 | PyObject *exception, |
| 109 | const char *format, /* ASCII-encoded string */ |
| 110 | ... |
| 111 | ); |
| 112 | |
| 113 | /* In exceptions.c */ |
| 114 | |
| 115 | PyAPI_FUNC(int) _PyException_AddNote( |
| 116 | PyObject *exc, |
| 117 | PyObject *note); |
| 118 | |
| 119 | PyAPI_FUNC(PyObject*) PyUnstable_Exc_PrepReraiseStar( |
| 120 | PyObject *orig, |
| 121 | PyObject *excs); |
| 122 | |
| 123 | /* In signalmodule.c */ |
| 124 | |
| 125 | int PySignal_SetWakeupFd(int fd); |
| 126 | PyAPI_FUNC(int) _PyErr_CheckSignals(void); |
| 127 | |
| 128 | /* Support for adding program text to SyntaxErrors */ |
| 129 | |
| 130 | PyAPI_FUNC(void) PyErr_SyntaxLocationObject( |
| 131 | PyObject *filename, |
| 132 | int lineno, |
| 133 | int col_offset); |
| 134 | |
| 135 | PyAPI_FUNC(void) PyErr_RangedSyntaxLocationObject( |
| 136 | PyObject *filename, |
| 137 | int lineno, |
| 138 | int col_offset, |
| 139 | int end_lineno, |
| 140 | int end_col_offset); |
| 141 | |
| 142 | PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject( |
| 143 | PyObject *filename, |
| 144 | int lineno); |
| 145 | |
| 146 | PyAPI_FUNC(PyObject *) _PyErr_ProgramDecodedTextObject( |
| 147 | PyObject *filename, |
| 148 | int lineno, |
| 149 | const char* encoding); |
| 150 | |
| 151 | PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create( |
| 152 | PyObject *object, |
| 153 | Py_ssize_t start, |
| 154 | Py_ssize_t end, |
| 155 | const char *reason /* UTF-8 encoded string */ |
| 156 | ); |
| 157 | |
| 158 | PyAPI_FUNC(void) _PyErr_WriteUnraisableMsg( |
| 159 | const char *err_msg, |
| 160 | PyObject *obj); |
| 161 | |
| 162 | PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFunc( |
| 163 | const char *func, |
| 164 | const char *message); |
| 165 | |
| 166 | PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat( |
| 167 | const char *func, |
| 168 | const char *format, |
| 169 | ...); |
| 170 | |
| 171 | extern PyObject *_PyErr_SetImportErrorWithNameFrom( |
| 172 | PyObject *, |
| 173 | PyObject *, |
| 174 | PyObject *, |
| 175 | PyObject *); |
| 176 | |
| 177 | |
| 178 | #define Py_FatalError(message) _Py_FatalErrorFunc(__func__, (message)) |
| 179 | |