1993-07-28 17:05:47 +08:00
|
|
|
#ifndef Py_ERRORS_H
|
|
|
|
#define Py_ERRORS_H
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
1991-02-19 20:39:46 +08:00
|
|
|
|
1990-10-14 20:07:46 +08:00
|
|
|
/* Error handling definitions */
|
|
|
|
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(void) PyErr_SetNone(PyObject *);
|
|
|
|
PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);
|
|
|
|
PyAPI_FUNC(void) PyErr_SetString(PyObject *, const char *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyErr_Occurred(void);
|
|
|
|
PyAPI_FUNC(void) PyErr_Clear(void);
|
|
|
|
PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
|
|
|
|
PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
|
1990-10-14 20:07:46 +08:00
|
|
|
|
Three new C API functions:
- int PyErr_GivenExceptionMatches(obj1, obj2)
Returns 1 if obj1 and obj2 are the same object, or if obj1 is an
instance of type obj2, or of a class derived from obj2
- int PyErr_ExceptionMatches(obj)
Higher level wrapper around PyErr_GivenExceptionMatches() which uses
PyErr_Occurred() as obj1. This will be the more commonly called
function.
- void PyErr_NormalizeException(typeptr, valptr, tbptr)
Normalizes exceptions, and places the normalized values in the
arguments. If type is not a class, this does nothing. If type is a
class, then it makes sure that value is an instance of the class by:
1. if instance is of the type, or a class derived from type, it does
nothing.
2. otherwise it instantiates the class, using the value as an
argument. If value is None, it uses an empty arg tuple, and if
the value is a tuple, it uses just that.
1997-08-23 05:22:58 +08:00
|
|
|
/* Error testing and normalization */
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
|
|
|
|
PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);
|
|
|
|
PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
|
Three new C API functions:
- int PyErr_GivenExceptionMatches(obj1, obj2)
Returns 1 if obj1 and obj2 are the same object, or if obj1 is an
instance of type obj2, or of a class derived from obj2
- int PyErr_ExceptionMatches(obj)
Higher level wrapper around PyErr_GivenExceptionMatches() which uses
PyErr_Occurred() as obj1. This will be the more commonly called
function.
- void PyErr_NormalizeException(typeptr, valptr, tbptr)
Normalizes exceptions, and places the normalized values in the
arguments. If type is not a class, this does nothing. If type is a
class, then it makes sure that value is an instance of the class by:
1. if instance is of the type, or a class derived from type, it does
nothing.
2. otherwise it instantiates the class, using the value as an
argument. If value is None, it uses an empty arg tuple, and if
the value is a tuple, it uses just that.
1997-08-23 05:22:58 +08:00
|
|
|
|
|
|
|
|
1990-12-20 23:06:42 +08:00
|
|
|
/* Predefined exceptions */
|
1990-10-15 04:00:25 +08:00
|
|
|
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_DATA(PyObject *) PyExc_Exception;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_StopIteration;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_StandardError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_ArithmeticError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_LookupError;
|
|
|
|
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_AssertionError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_AttributeError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_EOFError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_FloatingPointError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_EnvironmentError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_IOError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_OSError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_ImportError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_IndexError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_KeyError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_MemoryError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_NameError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_OverflowError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_RuntimeError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_SyntaxError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_IndentationError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_TabError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_ReferenceError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_SystemError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_SystemExit;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_TypeError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_UnboundLocalError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_UnicodeError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_ValueError;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError;
|
2000-02-17 23:17:18 +08:00
|
|
|
#ifdef MS_WINDOWS
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_DATA(PyObject *) PyExc_WindowsError;
|
2000-02-17 23:17:18 +08:00
|
|
|
#endif
|
1990-10-22 06:09:30 +08:00
|
|
|
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst;
|
1997-08-30 05:56:07 +08:00
|
|
|
|
2000-12-16 05:57:34 +08:00
|
|
|
/* Predefined warning categories */
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_DATA(PyObject *) PyExc_Warning;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_UserWarning;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_OverflowWarning;
|
|
|
|
PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
|
2002-08-14 23:51:29 +08:00
|
|
|
PyAPI_DATA(PyObject *) PyExc_FutureWarning;
|
2000-12-16 05:57:34 +08:00
|
|
|
|
1997-08-30 05:56:07 +08:00
|
|
|
|
1990-10-15 04:00:25 +08:00
|
|
|
/* Convenience functions */
|
|
|
|
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(int) PyErr_BadArgument(void);
|
|
|
|
PyAPI_FUNC(PyObject *) PyErr_NoMemory(void);
|
|
|
|
PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(PyObject *, char *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...)
|
2001-10-23 10:21:22 +08:00
|
|
|
__attribute__((format(printf, 2, 3)));
|
2000-02-17 23:17:18 +08:00
|
|
|
#ifdef MS_WINDOWS
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(int, const char *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
|
|
|
|
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
|
2002-07-29 22:27:41 +08:00
|
|
|
PyObject *,int, const char *);
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
|
2000-02-17 23:17:18 +08:00
|
|
|
#endif
|
1990-10-22 06:09:30 +08:00
|
|
|
|
2000-08-25 06:38:39 +08:00
|
|
|
/* Export the old function so that the existing API remains available: */
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(void) PyErr_BadInternalCall(void);
|
|
|
|
PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename, int lineno);
|
2000-08-25 06:38:39 +08:00
|
|
|
/* Mask the old API with a call to the new API for code compiled under
|
|
|
|
Python 2.0: */
|
|
|
|
#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
|
1993-05-19 22:50:45 +08:00
|
|
|
|
1997-09-17 05:50:37 +08:00
|
|
|
/* Function to create a new exception */
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(PyObject *) PyErr_NewException(char *name, PyObject *base,
|
2000-07-09 01:25:55 +08:00
|
|
|
PyObject *dict);
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
|
1997-09-17 05:50:37 +08:00
|
|
|
|
2000-12-16 05:57:34 +08:00
|
|
|
/* Issue a warning or exception */
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(int) PyErr_Warn(PyObject *, char *);
|
|
|
|
PyAPI_FUNC(int) PyErr_WarnExplicit(PyObject *, char *,
|
2001-03-01 05:44:20 +08:00
|
|
|
char *, int, char *, PyObject *);
|
2000-12-16 05:57:34 +08:00
|
|
|
|
1997-01-03 08:15:03 +08:00
|
|
|
/* In sigcheck.c or signalmodule.c */
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(int) PyErr_CheckSignals(void);
|
|
|
|
PyAPI_FUNC(void) PyErr_SetInterrupt(void);
|
2001-03-01 01:47:12 +08:00
|
|
|
|
|
|
|
/* Support for adding program text to SyntaxErrors */
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(void) PyErr_SyntaxLocation(char *, int);
|
|
|
|
PyAPI_FUNC(PyObject *) PyErr_ProgramText(char *, int);
|
2001-11-29 00:51:49 +08:00
|
|
|
|
2001-07-31 21:24:44 +08:00
|
|
|
/* These APIs aren't really part of the error implementation, but
|
|
|
|
often needed to format error messages; the native C lib APIs are
|
|
|
|
not available on all platforms, which is why we provide emulations
|
2001-11-29 00:51:49 +08:00
|
|
|
for those platforms in Python/mysnprintf.c,
|
|
|
|
WARNING: The return value of snprintf varies across platforms; do
|
|
|
|
not rely on any particular behavior; eventually the C99 defn may
|
|
|
|
be reliable.
|
|
|
|
*/
|
2001-07-31 21:24:44 +08:00
|
|
|
#if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
|
|
|
|
# define HAVE_SNPRINTF
|
|
|
|
# define snprintf _snprintf
|
|
|
|
# define vsnprintf _vsnprintf
|
|
|
|
#endif
|
2001-08-01 02:05:33 +08:00
|
|
|
|
2001-07-31 22:23:52 +08:00
|
|
|
#include <stdarg.h>
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...)
|
2001-10-23 10:21:22 +08:00
|
|
|
__attribute__((format(printf, 3, 4)));
|
2002-08-12 15:21:58 +08:00
|
|
|
PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
|
2001-10-23 10:21:22 +08:00
|
|
|
__attribute__((format(printf, 3, 0)));
|
1994-08-01 19:34:53 +08:00
|
|
|
|
1993-07-28 17:05:47 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* !Py_ERRORS_H */
|