pyerrors.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #ifndef Py_CPYTHON_ERRORS_H
  2. # error "this header file must not be included directly"
  3. #endif
  4. /* Error objects */
  5. /* PyException_HEAD defines the initial segment of every exception class. */
  6. #define PyException_HEAD PyObject_HEAD PyObject *dict;\
  7. PyObject *args; PyObject *notes; PyObject *traceback;\
  8. PyObject *context; PyObject *cause;\
  9. char suppress_context;
  10. typedef struct {
  11. PyException_HEAD
  12. } PyBaseExceptionObject;
  13. typedef struct {
  14. PyException_HEAD
  15. PyObject *msg;
  16. PyObject *excs;
  17. } PyBaseExceptionGroupObject;
  18. typedef struct {
  19. PyException_HEAD
  20. PyObject *msg;
  21. PyObject *filename;
  22. PyObject *lineno;
  23. PyObject *offset;
  24. PyObject *end_lineno;
  25. PyObject *end_offset;
  26. PyObject *text;
  27. PyObject *print_file_and_line;
  28. } PySyntaxErrorObject;
  29. typedef struct {
  30. PyException_HEAD
  31. PyObject *msg;
  32. PyObject *name;
  33. PyObject *path;
  34. PyObject *name_from;
  35. } PyImportErrorObject;
  36. typedef struct {
  37. PyException_HEAD
  38. PyObject *encoding;
  39. PyObject *object;
  40. Py_ssize_t start;
  41. Py_ssize_t end;
  42. PyObject *reason;
  43. } PyUnicodeErrorObject;
  44. typedef struct {
  45. PyException_HEAD
  46. PyObject *code;
  47. } PySystemExitObject;
  48. typedef struct {
  49. PyException_HEAD
  50. PyObject *myerrno;
  51. PyObject *strerror;
  52. PyObject *filename;
  53. PyObject *filename2;
  54. #ifdef MS_WINDOWS
  55. PyObject *winerror;
  56. #endif
  57. Py_ssize_t written; /* only for BlockingIOError, -1 otherwise */
  58. } PyOSErrorObject;
  59. typedef struct {
  60. PyException_HEAD
  61. PyObject *value;
  62. } PyStopIterationObject;
  63. typedef struct {
  64. PyException_HEAD
  65. PyObject *name;
  66. } PyNameErrorObject;
  67. typedef struct {
  68. PyException_HEAD
  69. PyObject *obj;
  70. PyObject *name;
  71. } PyAttributeErrorObject;
  72. /* Compatibility typedefs */
  73. typedef PyOSErrorObject PyEnvironmentErrorObject;
  74. #ifdef MS_WINDOWS
  75. typedef PyOSErrorObject PyWindowsErrorObject;
  76. #endif
  77. /* Error handling definitions */
  78. PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *);
  79. PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate);
  80. PyAPI_FUNC(PyObject*) _PyErr_GetHandledException(PyThreadState *);
  81. PyAPI_FUNC(void) _PyErr_SetHandledException(PyThreadState *, PyObject *);
  82. PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **);
  83. /* Context manipulation (PEP 3134) */
  84. Py_DEPRECATED(3.12) PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
  85. PyAPI_FUNC(void) _PyErr_ChainExceptions1(PyObject *);
  86. /* Like PyErr_Format(), but saves current exception as __context__ and
  87. __cause__.
  88. */
  89. PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
  90. PyObject *exception,
  91. const char *format, /* ASCII-encoded string */
  92. ...
  93. );
  94. /* In exceptions.c */
  95. PyAPI_FUNC(int) _PyException_AddNote(
  96. PyObject *exc,
  97. PyObject *note);
  98. PyAPI_FUNC(PyObject*) PyUnstable_Exc_PrepReraiseStar(
  99. PyObject *orig,
  100. PyObject *excs);
  101. /* In signalmodule.c */
  102. int PySignal_SetWakeupFd(int fd);
  103. PyAPI_FUNC(int) _PyErr_CheckSignals(void);
  104. /* Support for adding program text to SyntaxErrors */
  105. PyAPI_FUNC(void) PyErr_SyntaxLocationObject(
  106. PyObject *filename,
  107. int lineno,
  108. int col_offset);
  109. PyAPI_FUNC(void) PyErr_RangedSyntaxLocationObject(
  110. PyObject *filename,
  111. int lineno,
  112. int col_offset,
  113. int end_lineno,
  114. int end_col_offset);
  115. PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject(
  116. PyObject *filename,
  117. int lineno);
  118. PyAPI_FUNC(PyObject *) _PyErr_ProgramDecodedTextObject(
  119. PyObject *filename,
  120. int lineno,
  121. const char* encoding);
  122. PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
  123. PyObject *object,
  124. Py_ssize_t start,
  125. Py_ssize_t end,
  126. const char *reason /* UTF-8 encoded string */
  127. );
  128. PyAPI_FUNC(void) _PyErr_WriteUnraisableMsg(
  129. const char *err_msg,
  130. PyObject *obj);
  131. PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFunc(
  132. const char *func,
  133. const char *message);
  134. PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat(
  135. const char *func,
  136. const char *format,
  137. ...);
  138. extern PyObject *_PyErr_SetImportErrorWithNameFrom(
  139. PyObject *,
  140. PyObject *,
  141. PyObject *,
  142. PyObject *);
  143. #define Py_FatalError(message) _Py_FatalErrorFunc(__func__, (message))