Raising warnings

The PyErr_Warn(PyObject*category, char *message) function sends the warning pointed to by message to the user, which Python by default displays on standard error. The category parameter can be any of the following global warning variables:

PyExc_Warning PyExc_DeprecationWarning




Under normal circumstances PyErr_Warn returns 0, but if the user configures Python to escalate warnings to errors, then the function returns -1 to indicate that it raised an exception. If it does raise an exception, be sure to treat it like any other exception by releasing owned references and returning an error code from the current function. /

New ^ Warnings are new in Python 2.1.


PyErr_WarnExplicit(PyObject*category, char *message, char *filename, intlineno, char*module, PyObject*registry) lets you raise a warning and have complete control over all warning attributes. This function calls the warn_explicit function in the Python warnings module.

Chapter 5 covers the warning module through which you can control how Python handles warning messages.


0 0

Post a comment