pyerrors.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. #ifndef Py_ERRORS_H
  2. #define Py_ERRORS_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stdarg.h> // va_list
  7. /* Error handling definitions */
  8. PyAPI_FUNC(void) PyErr_SetNone(PyObject *);
  9. PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);
  10. PyAPI_FUNC(void) PyErr_SetString(
  11. PyObject *exception,
  12. const char *string /* decoded from utf-8 */
  13. );
  14. PyAPI_FUNC(PyObject *) PyErr_Occurred(void);
  15. PyAPI_FUNC(void) PyErr_Clear(void);
  16. PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
  17. PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
  18. PyAPI_FUNC(PyObject *) PyErr_GetRaisedException(void);
  19. PyAPI_FUNC(void) PyErr_SetRaisedException(PyObject *);
  20. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030b0000
  21. PyAPI_FUNC(PyObject*) PyErr_GetHandledException(void);
  22. PyAPI_FUNC(void) PyErr_SetHandledException(PyObject *);
  23. #endif
  24. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
  25. PyAPI_FUNC(void) PyErr_GetExcInfo(PyObject **, PyObject **, PyObject **);
  26. PyAPI_FUNC(void) PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *);
  27. #endif
  28. /* Defined in Python/pylifecycle.c
  29. The Py_FatalError() function is replaced with a macro which logs
  30. automatically the name of the current function, unless the Py_LIMITED_API
  31. macro is defined. */
  32. PyAPI_FUNC(void) _Py_NO_RETURN Py_FatalError(const char *message);
  33. /* Error testing and normalization */
  34. PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
  35. PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);
  36. PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
  37. /* Traceback manipulation (PEP 3134) */
  38. PyAPI_FUNC(int) PyException_SetTraceback(PyObject *, PyObject *);
  39. PyAPI_FUNC(PyObject *) PyException_GetTraceback(PyObject *);
  40. /* Cause manipulation (PEP 3134) */
  41. PyAPI_FUNC(PyObject *) PyException_GetCause(PyObject *);
  42. PyAPI_FUNC(void) PyException_SetCause(PyObject *, PyObject *);
  43. /* Context manipulation (PEP 3134) */
  44. PyAPI_FUNC(PyObject *) PyException_GetContext(PyObject *);
  45. PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *);
  46. PyAPI_FUNC(PyObject *) PyException_GetArgs(PyObject *);
  47. PyAPI_FUNC(void) PyException_SetArgs(PyObject *, PyObject *);
  48. /* */
  49. #define PyExceptionClass_Check(x) \
  50. (PyType_Check((x)) && \
  51. PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
  52. #define PyExceptionInstance_Check(x) \
  53. PyType_FastSubclass(Py_TYPE(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)
  54. PyAPI_FUNC(const char *) PyExceptionClass_Name(PyObject *);
  55. #define PyExceptionInstance_Class(x) _PyObject_CAST(Py_TYPE(x))
  56. #define _PyBaseExceptionGroup_Check(x) \
  57. PyObject_TypeCheck((x), (PyTypeObject *)PyExc_BaseExceptionGroup)
  58. /* Predefined exceptions */
  59. PyAPI_DATA(PyObject *) PyExc_BaseException;
  60. PyAPI_DATA(PyObject *) PyExc_Exception;
  61. PyAPI_DATA(PyObject *) PyExc_BaseExceptionGroup;
  62. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  63. PyAPI_DATA(PyObject *) PyExc_StopAsyncIteration;
  64. #endif
  65. PyAPI_DATA(PyObject *) PyExc_StopIteration;
  66. PyAPI_DATA(PyObject *) PyExc_GeneratorExit;
  67. PyAPI_DATA(PyObject *) PyExc_ArithmeticError;
  68. PyAPI_DATA(PyObject *) PyExc_LookupError;
  69. PyAPI_DATA(PyObject *) PyExc_AssertionError;
  70. PyAPI_DATA(PyObject *) PyExc_AttributeError;
  71. PyAPI_DATA(PyObject *) PyExc_BufferError;
  72. PyAPI_DATA(PyObject *) PyExc_EOFError;
  73. PyAPI_DATA(PyObject *) PyExc_FloatingPointError;
  74. PyAPI_DATA(PyObject *) PyExc_OSError;
  75. PyAPI_DATA(PyObject *) PyExc_ImportError;
  76. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000
  77. PyAPI_DATA(PyObject *) PyExc_ModuleNotFoundError;
  78. #endif
  79. PyAPI_DATA(PyObject *) PyExc_IndexError;
  80. PyAPI_DATA(PyObject *) PyExc_KeyError;
  81. PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt;
  82. PyAPI_DATA(PyObject *) PyExc_MemoryError;
  83. PyAPI_DATA(PyObject *) PyExc_NameError;
  84. PyAPI_DATA(PyObject *) PyExc_OverflowError;
  85. PyAPI_DATA(PyObject *) PyExc_RuntimeError;
  86. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  87. PyAPI_DATA(PyObject *) PyExc_RecursionError;
  88. #endif
  89. PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
  90. PyAPI_DATA(PyObject *) PyExc_SyntaxError;
  91. PyAPI_DATA(PyObject *) PyExc_IndentationError;
  92. PyAPI_DATA(PyObject *) PyExc_TabError;
  93. PyAPI_DATA(PyObject *) PyExc_ReferenceError;
  94. PyAPI_DATA(PyObject *) PyExc_SystemError;
  95. PyAPI_DATA(PyObject *) PyExc_SystemExit;
  96. PyAPI_DATA(PyObject *) PyExc_TypeError;
  97. PyAPI_DATA(PyObject *) PyExc_UnboundLocalError;
  98. PyAPI_DATA(PyObject *) PyExc_UnicodeError;
  99. PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError;
  100. PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError;
  101. PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError;
  102. PyAPI_DATA(PyObject *) PyExc_ValueError;
  103. PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError;
  104. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
  105. PyAPI_DATA(PyObject *) PyExc_BlockingIOError;
  106. PyAPI_DATA(PyObject *) PyExc_BrokenPipeError;
  107. PyAPI_DATA(PyObject *) PyExc_ChildProcessError;
  108. PyAPI_DATA(PyObject *) PyExc_ConnectionError;
  109. PyAPI_DATA(PyObject *) PyExc_ConnectionAbortedError;
  110. PyAPI_DATA(PyObject *) PyExc_ConnectionRefusedError;
  111. PyAPI_DATA(PyObject *) PyExc_ConnectionResetError;
  112. PyAPI_DATA(PyObject *) PyExc_FileExistsError;
  113. PyAPI_DATA(PyObject *) PyExc_FileNotFoundError;
  114. PyAPI_DATA(PyObject *) PyExc_InterruptedError;
  115. PyAPI_DATA(PyObject *) PyExc_IsADirectoryError;
  116. PyAPI_DATA(PyObject *) PyExc_NotADirectoryError;
  117. PyAPI_DATA(PyObject *) PyExc_PermissionError;
  118. PyAPI_DATA(PyObject *) PyExc_ProcessLookupError;
  119. PyAPI_DATA(PyObject *) PyExc_TimeoutError;
  120. #endif
  121. /* Compatibility aliases */
  122. PyAPI_DATA(PyObject *) PyExc_EnvironmentError;
  123. PyAPI_DATA(PyObject *) PyExc_IOError;
  124. #ifdef MS_WINDOWS
  125. PyAPI_DATA(PyObject *) PyExc_WindowsError;
  126. #endif
  127. /* Predefined warning categories */
  128. PyAPI_DATA(PyObject *) PyExc_Warning;
  129. PyAPI_DATA(PyObject *) PyExc_UserWarning;
  130. PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
  131. PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
  132. PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
  133. PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
  134. PyAPI_DATA(PyObject *) PyExc_FutureWarning;
  135. PyAPI_DATA(PyObject *) PyExc_ImportWarning;
  136. PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;
  137. PyAPI_DATA(PyObject *) PyExc_BytesWarning;
  138. PyAPI_DATA(PyObject *) PyExc_EncodingWarning;
  139. PyAPI_DATA(PyObject *) PyExc_ResourceWarning;
  140. /* Convenience functions */
  141. PyAPI_FUNC(int) PyErr_BadArgument(void);
  142. PyAPI_FUNC(PyObject *) PyErr_NoMemory(void);
  143. PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
  144. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(
  145. PyObject *, PyObject *);
  146. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
  147. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObjects(
  148. PyObject *, PyObject *, PyObject *);
  149. #endif
  150. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(
  151. PyObject *exc,
  152. const char *filename /* decoded from the filesystem encoding */
  153. );
  154. PyAPI_FUNC(PyObject *) PyErr_Format(
  155. PyObject *exception,
  156. const char *format, /* ASCII-encoded string */
  157. ...
  158. );
  159. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  160. PyAPI_FUNC(PyObject *) PyErr_FormatV(
  161. PyObject *exception,
  162. const char *format,
  163. va_list vargs);
  164. #endif
  165. #ifdef MS_WINDOWS
  166. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
  167. int ierr,
  168. const char *filename /* decoded from the filesystem encoding */
  169. );
  170. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
  171. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
  172. PyObject *,int, PyObject *);
  173. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
  174. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObjects(
  175. PyObject *,int, PyObject *, PyObject *);
  176. #endif
  177. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
  178. PyObject *exc,
  179. int ierr,
  180. const char *filename /* decoded from the filesystem encoding */
  181. );
  182. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
  183. #endif /* MS_WINDOWS */
  184. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000
  185. PyAPI_FUNC(PyObject *) PyErr_SetImportErrorSubclass(PyObject *, PyObject *,
  186. PyObject *, PyObject *);
  187. #endif
  188. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
  189. PyAPI_FUNC(PyObject *) PyErr_SetImportError(PyObject *, PyObject *,
  190. PyObject *);
  191. #endif
  192. /* Export the old function so that the existing API remains available: */
  193. PyAPI_FUNC(void) PyErr_BadInternalCall(void);
  194. PyAPI_FUNC(void) _PyErr_BadInternalCall(const char *filename, int lineno);
  195. /* Mask the old API with a call to the new API for code compiled under
  196. Python 2.0: */
  197. #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
  198. /* Function to create a new exception */
  199. PyAPI_FUNC(PyObject *) PyErr_NewException(
  200. const char *name, PyObject *base, PyObject *dict);
  201. PyAPI_FUNC(PyObject *) PyErr_NewExceptionWithDoc(
  202. const char *name, const char *doc, PyObject *base, PyObject *dict);
  203. PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
  204. /* In signalmodule.c */
  205. PyAPI_FUNC(int) PyErr_CheckSignals(void);
  206. PyAPI_FUNC(void) PyErr_SetInterrupt(void);
  207. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
  208. PyAPI_FUNC(int) PyErr_SetInterruptEx(int signum);
  209. #endif
  210. /* Support for adding program text to SyntaxErrors */
  211. PyAPI_FUNC(void) PyErr_SyntaxLocation(
  212. const char *filename, /* decoded from the filesystem encoding */
  213. int lineno);
  214. PyAPI_FUNC(void) PyErr_SyntaxLocationEx(
  215. const char *filename, /* decoded from the filesystem encoding */
  216. int lineno,
  217. int col_offset);
  218. PyAPI_FUNC(PyObject *) PyErr_ProgramText(
  219. const char *filename, /* decoded from the filesystem encoding */
  220. int lineno);
  221. /* The following functions are used to create and modify unicode
  222. exceptions from C */
  223. /* create a UnicodeDecodeError object */
  224. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create(
  225. const char *encoding, /* UTF-8 encoded string */
  226. const char *object,
  227. Py_ssize_t length,
  228. Py_ssize_t start,
  229. Py_ssize_t end,
  230. const char *reason /* UTF-8 encoded string */
  231. );
  232. /* get the encoding attribute */
  233. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *);
  234. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *);
  235. /* get the object attribute */
  236. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *);
  237. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *);
  238. PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *);
  239. /* get the value of the start attribute (the int * may not be NULL)
  240. return 0 on success, -1 on failure */
  241. PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *);
  242. PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *);
  243. PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *);
  244. /* assign a new value to the start attribute
  245. return 0 on success, -1 on failure */
  246. PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t);
  247. PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t);
  248. PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t);
  249. /* get the value of the end attribute (the int *may not be NULL)
  250. return 0 on success, -1 on failure */
  251. PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *);
  252. PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *);
  253. PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *);
  254. /* assign a new value to the end attribute
  255. return 0 on success, -1 on failure */
  256. PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t);
  257. PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t);
  258. PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t);
  259. /* get the value of the reason attribute */
  260. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *);
  261. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *);
  262. PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *);
  263. /* assign a new value to the reason attribute
  264. return 0 on success, -1 on failure */
  265. PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(
  266. PyObject *exc,
  267. const char *reason /* UTF-8 encoded string */
  268. );
  269. PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(
  270. PyObject *exc,
  271. const char *reason /* UTF-8 encoded string */
  272. );
  273. PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
  274. PyObject *exc,
  275. const char *reason /* UTF-8 encoded string */
  276. );
  277. PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...)
  278. Py_GCC_ATTRIBUTE((format(printf, 3, 4)));
  279. PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
  280. Py_GCC_ATTRIBUTE((format(printf, 3, 0)));
  281. #ifndef Py_LIMITED_API
  282. # define Py_CPYTHON_ERRORS_H
  283. # include "cpython/pyerrors.h"
  284. # undef Py_CPYTHON_ERRORS_H
  285. #endif
  286. #ifdef __cplusplus
  287. }
  288. #endif
  289. #endif /* !Py_ERRORS_H */