(root)/
Python-3.11.7/
Include/
cpython/
pyerrors.h
       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  } PyImportErrorObject;
      41  
      42  typedef 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  
      51  typedef struct {
      52      PyException_HEAD
      53      PyObject *code;
      54  } PySystemExitObject;
      55  
      56  typedef 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  
      68  typedef struct {
      69      PyException_HEAD
      70      PyObject *value;
      71  } PyStopIterationObject;
      72  
      73  typedef struct {
      74      PyException_HEAD
      75      PyObject *name;
      76  } PyNameErrorObject;
      77  
      78  typedef struct {
      79      PyException_HEAD
      80      PyObject *obj;
      81      PyObject *name;
      82  } PyAttributeErrorObject;
      83  
      84  /* Compatibility typedefs */
      85  typedef PyOSErrorObject PyEnvironmentErrorObject;
      86  #ifdef MS_WINDOWS
      87  typedef PyOSErrorObject PyWindowsErrorObject;
      88  #endif
      89  
      90  /* Error handling definitions */
      91  
      92  PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *);
      93  PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate);
      94  PyAPI_FUNC(PyObject*) _PyErr_GetHandledException(PyThreadState *);
      95  PyAPI_FUNC(void) _PyErr_SetHandledException(PyThreadState *, PyObject *);
      96  PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **);
      97  
      98  /* Context manipulation (PEP 3134) */
      99  
     100  PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
     101  
     102  /* Like PyErr_Format(), but saves current exception as __context__ and
     103     __cause__.
     104   */
     105  PyAPI_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   */
     126  PyAPI_FUNC(PyObject *) _PyErr_TrySetFromCause(
     127      const char *prefix_format,   /* ASCII-encoded string  */
     128      ...
     129      );
     130  
     131  /* In signalmodule.c */
     132  
     133  int PySignal_SetWakeupFd(int fd);
     134  PyAPI_FUNC(int) _PyErr_CheckSignals(void);
     135  
     136  /* Support for adding program text to SyntaxErrors */
     137  
     138  PyAPI_FUNC(void) PyErr_SyntaxLocationObject(
     139      PyObject *filename,
     140      int lineno,
     141      int col_offset);
     142  
     143  PyAPI_FUNC(void) PyErr_RangedSyntaxLocationObject(
     144      PyObject *filename,
     145      int lineno,
     146      int col_offset,
     147      int end_lineno,
     148      int end_col_offset);
     149  
     150  PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject(
     151      PyObject *filename,
     152      int lineno);
     153  
     154  PyAPI_FUNC(PyObject *) _PyErr_ProgramDecodedTextObject(
     155      PyObject *filename,
     156      int lineno,
     157      const char* encoding);
     158  
     159  PyAPI_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  
     166  PyAPI_FUNC(void) _PyErr_WriteUnraisableMsg(
     167      const char *err_msg,
     168      PyObject *obj);
     169  
     170  PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFunc(
     171      const char *func,
     172      const char *message);
     173  
     174  PyAPI_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)