blob: 1ee4fe2fab0572cdadead1bf94e89c0ead5cdd4e [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_ERRORS_H
2#define Py_ERRORS_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossumf70e43a1991-02-19 12:39:46 +00007
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00008/* Error handling definitions */
9
Fred Draked5c84ed2000-07-08 17:25:55 +000010DL_IMPORT(void) PyErr_SetNone(PyObject *);
11DL_IMPORT(void) PyErr_SetObject(PyObject *, PyObject *);
12DL_IMPORT(void) PyErr_SetString(PyObject *, const char *);
13DL_IMPORT(PyObject *) PyErr_Occurred(void);
14DL_IMPORT(void) PyErr_Clear(void);
15DL_IMPORT(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
16DL_IMPORT(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000017
Barry Warsawc0dc92a1997-08-22 21:22:58 +000018/* Error testing and normalization */
Fred Draked5c84ed2000-07-08 17:25:55 +000019DL_IMPORT(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
20DL_IMPORT(int) PyErr_ExceptionMatches(PyObject *);
21DL_IMPORT(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
Barry Warsawc0dc92a1997-08-22 21:22:58 +000022
23
Guido van Rossum3f5da241990-12-20 15:06:42 +000024/* Predefined exceptions */
Guido van Rossum5c600e11990-10-14 20:00:25 +000025
Guido van Rossum04748321997-09-16 18:43:15 +000026extern DL_IMPORT(PyObject *) PyExc_Exception;
Guido van Rossum59d1d2b2001-04-20 19:13:02 +000027extern DL_IMPORT(PyObject *) PyExc_StopIteration;
Barry Warsaw392d8271997-08-29 21:56:07 +000028extern DL_IMPORT(PyObject *) PyExc_StandardError;
Barry Warsaw65349a31997-09-16 21:50:36 +000029extern DL_IMPORT(PyObject *) PyExc_ArithmeticError;
Barry Warsaw392d8271997-08-29 21:56:07 +000030extern DL_IMPORT(PyObject *) PyExc_LookupError;
31
Guido van Rossum6fa44661997-04-02 05:22:53 +000032extern DL_IMPORT(PyObject *) PyExc_AssertionError;
Guido van Rossum051ab121995-02-27 10:17:52 +000033extern DL_IMPORT(PyObject *) PyExc_AttributeError;
Guido van Rossum051ab121995-02-27 10:17:52 +000034extern DL_IMPORT(PyObject *) PyExc_EOFError;
Guido van Rossum7d4266e1997-02-14 22:53:12 +000035extern DL_IMPORT(PyObject *) PyExc_FloatingPointError;
Barry Warsaw62a21a21998-07-23 15:57:34 +000036extern DL_IMPORT(PyObject *) PyExc_EnvironmentError;
Guido van Rossum051ab121995-02-27 10:17:52 +000037extern DL_IMPORT(PyObject *) PyExc_IOError;
Barry Warsaw62a21a21998-07-23 15:57:34 +000038extern DL_IMPORT(PyObject *) PyExc_OSError;
Guido van Rossum051ab121995-02-27 10:17:52 +000039extern DL_IMPORT(PyObject *) PyExc_ImportError;
40extern DL_IMPORT(PyObject *) PyExc_IndexError;
41extern DL_IMPORT(PyObject *) PyExc_KeyError;
42extern DL_IMPORT(PyObject *) PyExc_KeyboardInterrupt;
43extern DL_IMPORT(PyObject *) PyExc_MemoryError;
44extern DL_IMPORT(PyObject *) PyExc_NameError;
45extern DL_IMPORT(PyObject *) PyExc_OverflowError;
46extern DL_IMPORT(PyObject *) PyExc_RuntimeError;
Barry Warsawd052ff01998-12-01 18:34:01 +000047extern DL_IMPORT(PyObject *) PyExc_NotImplementedError;
Guido van Rossum051ab121995-02-27 10:17:52 +000048extern DL_IMPORT(PyObject *) PyExc_SyntaxError;
Fred Draked5c84ed2000-07-08 17:25:55 +000049extern DL_IMPORT(PyObject *) PyExc_IndentationError;
50extern DL_IMPORT(PyObject *) PyExc_TabError;
Guido van Rossum051ab121995-02-27 10:17:52 +000051extern DL_IMPORT(PyObject *) PyExc_SystemError;
52extern DL_IMPORT(PyObject *) PyExc_SystemExit;
53extern DL_IMPORT(PyObject *) PyExc_TypeError;
Guido van Rossum87460821999-06-22 14:47:32 +000054extern DL_IMPORT(PyObject *) PyExc_UnboundLocalError;
Guido van Rossum99cc9712000-03-10 22:33:32 +000055extern DL_IMPORT(PyObject *) PyExc_UnicodeError;
Guido van Rossum051ab121995-02-27 10:17:52 +000056extern DL_IMPORT(PyObject *) PyExc_ValueError;
57extern DL_IMPORT(PyObject *) PyExc_ZeroDivisionError;
Guido van Rossumdb0c9f72000-02-17 15:17:18 +000058#ifdef MS_WINDOWS
59extern DL_IMPORT(PyObject *) PyExc_WindowsError;
60#endif
Guido van Rossum3e55cb61990-10-21 22:09:30 +000061
Barry Warsaw392d8271997-08-29 21:56:07 +000062extern DL_IMPORT(PyObject *) PyExc_MemoryErrorInst;
63
Guido van Rossum3fc30372000-12-15 21:57:34 +000064/* Predefined warning categories */
65extern DL_IMPORT(PyObject *) PyExc_Warning;
66extern DL_IMPORT(PyObject *) PyExc_UserWarning;
67extern DL_IMPORT(PyObject *) PyExc_DeprecationWarning;
68extern DL_IMPORT(PyObject *) PyExc_SyntaxWarning;
69extern DL_IMPORT(PyObject *) PyExc_RuntimeWarning;
70
Barry Warsaw392d8271997-08-29 21:56:07 +000071
Guido van Rossum5c600e11990-10-14 20:00:25 +000072/* Convenience functions */
73
Fred Draked5c84ed2000-07-08 17:25:55 +000074extern DL_IMPORT(int) PyErr_BadArgument(void);
75extern DL_IMPORT(PyObject *) PyErr_NoMemory(void);
76extern DL_IMPORT(PyObject *) PyErr_SetFromErrno(PyObject *);
77extern DL_IMPORT(PyObject *) PyErr_SetFromErrnoWithFilename(PyObject *, char *);
78extern DL_IMPORT(PyObject *) PyErr_Format(PyObject *, const char *, ...);
Guido van Rossumdb0c9f72000-02-17 15:17:18 +000079#ifdef MS_WINDOWS
80extern DL_IMPORT(PyObject *) PyErr_SetFromWindowsErrWithFilename(int, const char *);
81extern DL_IMPORT(PyObject *) PyErr_SetFromWindowsErr(int);
82#endif
Guido van Rossum3e55cb61990-10-21 22:09:30 +000083
Fred Drake6d63adf2000-08-24 22:38:39 +000084/* Export the old function so that the existing API remains available: */
Fred Draked5c84ed2000-07-08 17:25:55 +000085extern DL_IMPORT(void) PyErr_BadInternalCall(void);
Fred Drake6d63adf2000-08-24 22:38:39 +000086extern DL_IMPORT(void) _PyErr_BadInternalCall(char *filename, int lineno);
87/* Mask the old API with a call to the new API for code compiled under
88 Python 2.0: */
89#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
Guido van Rossum25831651993-05-19 14:50:45 +000090
Guido van Rossum2d2c3441997-09-16 21:50:37 +000091/* Function to create a new exception */
Fred Draked5c84ed2000-07-08 17:25:55 +000092DL_IMPORT(PyObject *) PyErr_NewException(char *name, PyObject *base,
93 PyObject *dict);
Jeremy Hyltonb709df32000-09-01 02:47:25 +000094extern DL_IMPORT(void) PyErr_WriteUnraisable(PyObject *);
Guido van Rossum2d2c3441997-09-16 21:50:37 +000095
Guido van Rossum3fc30372000-12-15 21:57:34 +000096/* Issue a warning or exception */
97extern DL_IMPORT(int) PyErr_Warn(PyObject *, char *);
Guido van Rossum1bcb7e92001-02-28 21:44:20 +000098extern DL_IMPORT(int) PyErr_WarnExplicit(PyObject *, char *,
99 char *, int, char *, PyObject *);
Guido van Rossum3fc30372000-12-15 21:57:34 +0000100
Barry Warsawf3f41a91997-01-03 00:15:03 +0000101/* In sigcheck.c or signalmodule.c */
Fred Draked5c84ed2000-07-08 17:25:55 +0000102extern DL_IMPORT(int) PyErr_CheckSignals(void);
103extern DL_IMPORT(void) PyErr_SetInterrupt(void);
Jeremy Hyltonad3d3f22001-02-28 17:47:12 +0000104
105/* Support for adding program text to SyntaxErrors */
106extern DL_IMPORT(void) PyErr_SyntaxLocation(char *, int);
107extern DL_IMPORT(PyObject *) PyErr_ProgramText(char *, int);
Barry Warsawf3f41a91997-01-03 00:15:03 +0000108
Marc-André Lemburge5006eb2001-07-31 13:24:44 +0000109/* These APIs aren't really part of the error implementation, but
110 often needed to format error messages; the native C lib APIs are
111 not available on all platforms, which is why we provide emulations
112 for those platforms in Python/mysnprintf.c */
113#if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
114# define HAVE_SNPRINTF
115# define snprintf _snprintf
116# define vsnprintf _vsnprintf
117#endif
Marc-André Lemburg03d1b182001-07-31 18:05:33 +0000118
119/* Always enable the fallback solution during the 2.2.0 alpha cycle
120 for enhanced testing */
121#if PY_VERSION_HEX < 0x020200B0
122# undef HAVE_SNPRINTF
123#endif
124
Marc-André Lemburge5006eb2001-07-31 13:24:44 +0000125#ifndef HAVE_SNPRINTF
Marc-André Lemburgcecd9e02001-07-31 14:23:52 +0000126#include <stdarg.h>
Marc-André Lemburge5006eb2001-07-31 13:24:44 +0000127extern DL_IMPORT(int) PyOS_snprintf(char *str, size_t size, const char *format, ...);
128extern DL_IMPORT(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va);
129#else
130# define PyOS_vsnprintf vsnprintf
131# define PyOS_snprintf snprintf
132#endif
Guido van Rossumb6775db1994-08-01 11:34:53 +0000133
Guido van Rossuma3309961993-07-28 09:05:47 +0000134#ifdef __cplusplus
135}
136#endif
137#endif /* !Py_ERRORS_H */