blob: c3960b7e593154bec06c7c4ef2c68273eb09a0c1 [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;
Fred Drakebb9fa212001-10-05 21:50:08 +000051extern DL_IMPORT(PyObject *) PyExc_ReferenceError;
Guido van Rossum051ab121995-02-27 10:17:52 +000052extern DL_IMPORT(PyObject *) PyExc_SystemError;
53extern DL_IMPORT(PyObject *) PyExc_SystemExit;
54extern DL_IMPORT(PyObject *) PyExc_TypeError;
Guido van Rossum87460821999-06-22 14:47:32 +000055extern DL_IMPORT(PyObject *) PyExc_UnboundLocalError;
Guido van Rossum99cc9712000-03-10 22:33:32 +000056extern DL_IMPORT(PyObject *) PyExc_UnicodeError;
Guido van Rossum051ab121995-02-27 10:17:52 +000057extern DL_IMPORT(PyObject *) PyExc_ValueError;
58extern DL_IMPORT(PyObject *) PyExc_ZeroDivisionError;
Guido van Rossumdb0c9f72000-02-17 15:17:18 +000059#ifdef MS_WINDOWS
60extern DL_IMPORT(PyObject *) PyExc_WindowsError;
61#endif
Guido van Rossum3e55cb61990-10-21 22:09:30 +000062
Barry Warsaw392d8271997-08-29 21:56:07 +000063extern DL_IMPORT(PyObject *) PyExc_MemoryErrorInst;
64
Guido van Rossum3fc30372000-12-15 21:57:34 +000065/* Predefined warning categories */
66extern DL_IMPORT(PyObject *) PyExc_Warning;
67extern DL_IMPORT(PyObject *) PyExc_UserWarning;
68extern DL_IMPORT(PyObject *) PyExc_DeprecationWarning;
69extern DL_IMPORT(PyObject *) PyExc_SyntaxWarning;
Guido van Rossumae347b32001-08-23 02:56:07 +000070extern DL_IMPORT(PyObject *) PyExc_OverflowWarning;
Guido van Rossum3fc30372000-12-15 21:57:34 +000071extern DL_IMPORT(PyObject *) PyExc_RuntimeWarning;
72
Barry Warsaw392d8271997-08-29 21:56:07 +000073
Guido van Rossum5c600e11990-10-14 20:00:25 +000074/* Convenience functions */
75
Fred Draked5c84ed2000-07-08 17:25:55 +000076extern DL_IMPORT(int) PyErr_BadArgument(void);
77extern DL_IMPORT(PyObject *) PyErr_NoMemory(void);
78extern DL_IMPORT(PyObject *) PyErr_SetFromErrno(PyObject *);
79extern DL_IMPORT(PyObject *) PyErr_SetFromErrnoWithFilename(PyObject *, char *);
80extern DL_IMPORT(PyObject *) PyErr_Format(PyObject *, const char *, ...);
Guido van Rossumdb0c9f72000-02-17 15:17:18 +000081#ifdef MS_WINDOWS
82extern DL_IMPORT(PyObject *) PyErr_SetFromWindowsErrWithFilename(int, const char *);
83extern DL_IMPORT(PyObject *) PyErr_SetFromWindowsErr(int);
84#endif
Guido van Rossum3e55cb61990-10-21 22:09:30 +000085
Fred Drake6d63adf2000-08-24 22:38:39 +000086/* Export the old function so that the existing API remains available: */
Fred Draked5c84ed2000-07-08 17:25:55 +000087extern DL_IMPORT(void) PyErr_BadInternalCall(void);
Fred Drake6d63adf2000-08-24 22:38:39 +000088extern DL_IMPORT(void) _PyErr_BadInternalCall(char *filename, int lineno);
89/* Mask the old API with a call to the new API for code compiled under
90 Python 2.0: */
91#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
Guido van Rossum25831651993-05-19 14:50:45 +000092
Guido van Rossum2d2c3441997-09-16 21:50:37 +000093/* Function to create a new exception */
Fred Draked5c84ed2000-07-08 17:25:55 +000094DL_IMPORT(PyObject *) PyErr_NewException(char *name, PyObject *base,
95 PyObject *dict);
Jeremy Hyltonb709df32000-09-01 02:47:25 +000096extern DL_IMPORT(void) PyErr_WriteUnraisable(PyObject *);
Guido van Rossum2d2c3441997-09-16 21:50:37 +000097
Guido van Rossum3fc30372000-12-15 21:57:34 +000098/* Issue a warning or exception */
99extern DL_IMPORT(int) PyErr_Warn(PyObject *, char *);
Guido van Rossum1bcb7e92001-02-28 21:44:20 +0000100extern DL_IMPORT(int) PyErr_WarnExplicit(PyObject *, char *,
101 char *, int, char *, PyObject *);
Guido van Rossum3fc30372000-12-15 21:57:34 +0000102
Barry Warsawf3f41a91997-01-03 00:15:03 +0000103/* In sigcheck.c or signalmodule.c */
Fred Draked5c84ed2000-07-08 17:25:55 +0000104extern DL_IMPORT(int) PyErr_CheckSignals(void);
105extern DL_IMPORT(void) PyErr_SetInterrupt(void);
Jeremy Hyltonad3d3f22001-02-28 17:47:12 +0000106
107/* Support for adding program text to SyntaxErrors */
108extern DL_IMPORT(void) PyErr_SyntaxLocation(char *, int);
109extern DL_IMPORT(PyObject *) PyErr_ProgramText(char *, int);
Barry Warsawf3f41a91997-01-03 00:15:03 +0000110
Marc-André Lemburge5006eb2001-07-31 13:24:44 +0000111/* These APIs aren't really part of the error implementation, but
112 often needed to format error messages; the native C lib APIs are
113 not available on all platforms, which is why we provide emulations
114 for those platforms in Python/mysnprintf.c */
115#if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
116# define HAVE_SNPRINTF
117# define snprintf _snprintf
118# define vsnprintf _vsnprintf
119#endif
Marc-André Lemburg03d1b182001-07-31 18:05:33 +0000120
121/* Always enable the fallback solution during the 2.2.0 alpha cycle
122 for enhanced testing */
123#if PY_VERSION_HEX < 0x020200B0
124# undef HAVE_SNPRINTF
125#endif
126
Marc-André Lemburge5006eb2001-07-31 13:24:44 +0000127#ifndef HAVE_SNPRINTF
Marc-André Lemburgcecd9e02001-07-31 14:23:52 +0000128#include <stdarg.h>
Marc-André Lemburge5006eb2001-07-31 13:24:44 +0000129extern DL_IMPORT(int) PyOS_snprintf(char *str, size_t size, const char *format, ...);
130extern DL_IMPORT(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va);
131#else
132# define PyOS_vsnprintf vsnprintf
133# define PyOS_snprintf snprintf
134#endif
Guido van Rossumb6775db1994-08-01 11:34:53 +0000135
Guido van Rossuma3309961993-07-28 09:05:47 +0000136#ifdef __cplusplus
137}
138#endif
139#endif /* !Py_ERRORS_H */