pyerrors.h 5.0 KB

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