pyerrors.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. _PyErr_StackItem *_PyErr_GetTopmostException(PyThreadState *tstate);
  66. /* Context manipulation (PEP 3134) */
  67. PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
  68. /* */
  69. #define PyExceptionClass_Name(x) (((PyTypeObject*)(x))->tp_name)
  70. /* Convenience functions */
  71. #ifdef MS_WINDOWS
  72. Py_DEPRECATED(3.3)
  73. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
  74. PyObject *, const Py_UNICODE *);
  75. #endif /* MS_WINDOWS */
  76. /* Like PyErr_Format(), but saves current exception as __context__ and
  77. __cause__.
  78. */
  79. PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
  80. PyObject *exception,
  81. const char *format, /* ASCII-encoded string */
  82. ...
  83. );
  84. #ifdef MS_WINDOWS
  85. /* XXX redeclare to use WSTRING */
  86. Py_DEPRECATED(3.3)
  87. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
  88. int, const Py_UNICODE *);
  89. Py_DEPRECATED(3.3)
  90. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
  91. PyObject *,int, const Py_UNICODE *);
  92. #endif
  93. /* In exceptions.c */
  94. /* Helper that attempts to replace the current exception with one of the
  95. * same type but with a prefix added to the exception text. The resulting
  96. * exception description looks like:
  97. *
  98. * prefix (exc_type: original_exc_str)
  99. *
  100. * Only some exceptions can be safely replaced. If the function determines
  101. * it isn't safe to perform the replacement, it will leave the original
  102. * unmodified exception in place.
  103. *
  104. * Returns a borrowed reference to the new exception (if any), NULL if the
  105. * existing exception was left in place.
  106. */
  107. PyAPI_FUNC(PyObject *) _PyErr_TrySetFromCause(
  108. const char *prefix_format, /* ASCII-encoded string */
  109. ...
  110. );
  111. /* In signalmodule.c */
  112. int PySignal_SetWakeupFd(int fd);
  113. PyAPI_FUNC(int) _PyErr_CheckSignals(void);
  114. /* Support for adding program text to SyntaxErrors */
  115. PyAPI_FUNC(void) PyErr_SyntaxLocationObject(
  116. PyObject *filename,
  117. int lineno,
  118. int col_offset);
  119. PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject(
  120. PyObject *filename,
  121. int lineno);
  122. /* Create a UnicodeEncodeError object */
  123. Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
  124. const char *encoding, /* UTF-8 encoded string */
  125. const Py_UNICODE *object,
  126. Py_ssize_t length,
  127. Py_ssize_t start,
  128. Py_ssize_t end,
  129. const char *reason /* UTF-8 encoded string */
  130. );
  131. /* Create a UnicodeTranslateError object */
  132. Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
  133. const Py_UNICODE *object,
  134. Py_ssize_t length,
  135. Py_ssize_t start,
  136. Py_ssize_t end,
  137. const char *reason /* UTF-8 encoded string */
  138. );
  139. PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
  140. PyObject *object,
  141. Py_ssize_t start,
  142. Py_ssize_t end,
  143. const char *reason /* UTF-8 encoded string */
  144. );
  145. PyAPI_FUNC(void) _PyErr_WriteUnraisableMsg(
  146. const char *err_msg,
  147. PyObject *obj);
  148. #ifdef __cplusplus
  149. }
  150. #endif