pyerrors.h 5.3 KB

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