1993-07-28 06:05:47 -03:00
|
|
|
#ifndef Py_ERRORS_H
|
|
|
|
#define Py_ERRORS_H
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
1991-02-19 08:39:46 -04:00
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
/* Error handling definitions */
|
|
|
|
|
2002-08-12 04:21:58 -03: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 09:07:46 -03: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-22 18:22:58 -03:00
|
|
|
/* Error testing and normalization */
|
2002-08-12 04:21:58 -03: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-22 18:22:58 -03:00
|
|
|
|
|
|
|
|
1990-12-20 11:06:42 -04:00
|
|
|
/* Predefined exceptions */
|
1990-10-14 17:00:25 -03:00
|
|
|
|
2002-08-12 04:21:58 -03: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 11:17:18 -04:00
|
|
|
#ifdef MS_WINDOWS
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_DATA(PyObject *) PyExc_WindowsError;
|
2000-02-17 11:17:18 -04:00
|
|
|
#endif
|
1990-10-21 19:09:30 -03:00
|
|
|
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst;
|
1997-08-29 18:56:07 -03:00
|
|
|
|
2000-12-15 17:57:34 -04:00
|
|
|
/* Predefined warning categories */
|
2002-08-12 04:21:58 -03: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 12:51:29 -03:00
|
|
|
PyAPI_DATA(PyObject *) PyExc_FutureWarning;
|
2000-12-15 17:57:34 -04:00
|
|
|
|
1997-08-29 18:56:07 -03:00
|
|
|
|
1990-10-14 17:00:25 -03:00
|
|
|
/* Convenience functions */
|
|
|
|
|
2002-08-12 04:21:58 -03: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-22 23:21:22 -03:00
|
|
|
__attribute__((format(printf, 2, 3)));
|
2000-02-17 11:17:18 -04:00
|
|
|
#ifdef MS_WINDOWS
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(int, const char *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
|
|
|
|
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
|
2002-07-29 11:27:41 -03:00
|
|
|
PyObject *,int, const char *);
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
|
2000-02-17 11:17:18 -04:00
|
|
|
#endif
|
1990-10-21 19:09:30 -03:00
|
|
|
|
2000-08-24 19:38:39 -03:00
|
|
|
/* Export the old function so that the existing API remains available: */
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(void) PyErr_BadInternalCall(void);
|
|
|
|
PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename, int lineno);
|
2000-08-24 19:38:39 -03: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 11:50:45 -03:00
|
|
|
|
1997-09-16 18:50:37 -03:00
|
|
|
/* Function to create a new exception */
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(PyObject *) PyErr_NewException(char *name, PyObject *base,
|
2000-07-08 14:25:55 -03:00
|
|
|
PyObject *dict);
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
|
1997-09-16 18:50:37 -03:00
|
|
|
|
2000-12-15 17:57:34 -04:00
|
|
|
/* Issue a warning or exception */
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(int) PyErr_Warn(PyObject *, char *);
|
|
|
|
PyAPI_FUNC(int) PyErr_WarnExplicit(PyObject *, char *,
|
2001-02-28 17:44:20 -04:00
|
|
|
char *, int, char *, PyObject *);
|
2000-12-15 17:57:34 -04:00
|
|
|
|
1997-01-02 20:15:03 -04:00
|
|
|
/* In sigcheck.c or signalmodule.c */
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(int) PyErr_CheckSignals(void);
|
|
|
|
PyAPI_FUNC(void) PyErr_SetInterrupt(void);
|
2001-02-28 13:47:12 -04:00
|
|
|
|
|
|
|
/* Support for adding program text to SyntaxErrors */
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(void) PyErr_SyntaxLocation(char *, int);
|
|
|
|
PyAPI_FUNC(PyObject *) PyErr_ProgramText(char *, int);
|
2001-11-28 12:51:49 -04:00
|
|
|
|
2001-07-31 10:24:44 -03: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-28 12:51:49 -04: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 10:24:44 -03:00
|
|
|
#if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
|
|
|
|
# define HAVE_SNPRINTF
|
|
|
|
# define snprintf _snprintf
|
|
|
|
# define vsnprintf _vsnprintf
|
|
|
|
#endif
|
2001-07-31 15:05:33 -03:00
|
|
|
|
2001-07-31 11:23:52 -03:00
|
|
|
#include <stdarg.h>
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...)
|
2001-10-22 23:21:22 -03:00
|
|
|
__attribute__((format(printf, 3, 4)));
|
2002-08-12 04:21:58 -03:00
|
|
|
PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
|
2001-10-22 23:21:22 -03:00
|
|
|
__attribute__((format(printf, 3, 0)));
|
1994-08-01 08:34:53 -03:00
|
|
|
|
1993-07-28 06:05:47 -03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* !Py_ERRORS_H */
|